How does xpath specify a class while specifying which one to choose at the same time?

I already know that the way to write a specified class is: / / * [@ class="class"]
and I already know that the way to choose the first one is: / / div [n]
what should be the combination of the two? For example, select the last element of class="class".
ask for advice.

tried to write:

Mar.14,2021

xpath syntax can do what you want without having to recreate the wheel.

for example, locate the last H2 element that contains the class title . Xpath can do this

(//h2[@class="title"])[last()]

Please be sure to use parentheses because [] has a higher priority.

< hr >

by the way, in the Google browser developer tool (console, opens by pressing F12), you can execute xpath queries using $x (.) .

reference

xpath grammar document, https://www.w3schools.com/xml.


modify the answer based on the following answer

// 
//*[@class='class'][last()] // 
(//*[@class='class'])[last()] // div [last-1]
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b381eb-40676.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b381eb-40676.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?