<div class="boxen checkedzahlen" id="box41_0_1">
41
<input type="checkbox" value="1" name="cb41_0_1" id="cb41_0_1" checked="checked"/>
</div>
Something like this is given, how can I animate the text 41
, if $(this)
(the class boxen
) is clicked?
this > *
doesn't work. Neither does this:children
.
Answer: Use the jQuery text() method You can simply use the jQuery text() method to get all the text content inside an element. The text() method also return the text content of child elements.
To get the value of div content in jQuery, use the text() method. The text( ) method gets the combined text contents of all matched elements. This method works for both on XML and XHTML documents.
Use the textContent property to get the text of an html element, e.g. const text = box. textContent . The textContent property returns the text content of the element and its descendants. If the element is empty, an empty string is returned.
To select a span containing a specific text value using jQuery, we can select all the spans and then use the filter method to find the one with the given text value. We call $(“span”) to get all the spans. Then we spread the spans into an array with the spread operator.
Because of the slightly confusing title, some people (like me) may be coming to this question looking for how to get the textual content of a DOM element. You can accomplish this by:
$("#myselector").text() // returns the content of the element as plain text
$("#divID").html() would get the text inside.
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