Quick jQuery selector question :
I need to get the content of the first element (div
/span
/...) having a class
containing a string (eg : "price").
Something not like this ;o) :
var price = ( $('[class*=price]').text() );
Thanks a lot !!!
The :contains() selector selects elements containing the specified string. The string can be contained directly in the element as text, or in a child element.
The jQuery #id selector uses the id attribute of an HTML tag to find the specific element. An id should be unique within a page, so you should use the #id selector when you want to find a single, unique element.
The :first selector selects the first element. Note: This selector can only select one single element. Use the :first-child selector to select more than one element (one for each parent). This is mostly used together with another selector to select the first element in a group (like in the example above).
This should work fine using the first selector:
$('[class*="price"]:first').text()
http://jsfiddle.net/Et3vx/1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With