I have this span
<a title="Prev" data-event="click" data-handler="prev" class="ui-datepicker-prev ui-corner-all"> <span class="ui-icon ui-icon-circle-triangle-w">Prev</span> </a>
I need to set the text of the span to be <<
instead of its current text Prev
.
I tried this below, but it didn't change the text as I'd expected. How can this be done?
$(".ui-icon .ui-icon-circle-triangle-w").html('<<');
jQuery: Set a value in a span Set a value in a span using jQuery. JavaScript Code: $(document). ready(function(){ $('#button1').
Use innerText is the best method. As you can see in the MDM Docs innerText is the best way to retrieve and change the text of a <span> HTML element via Javascript.
The <span> HTML element is a generic inline container for phrasing content, which does not inherently represent anything. It can be used to group elements for styling purposes (using the class or id attributes), or because they share attribute values, such as lang .
The <span> tag is an inline container used to mark up a part of a text, or a part of a document. The <span> tag is easily styled by CSS or manipulated with JavaScript using the class or id attribute. The <span> tag is much like the <div> element, but <div> is a block-level element and <span> is an inline element.
Use .text()
instead, and change your selector:
$(".ui-datepicker-prev .ui-icon.ui-icon-circle-triangle-w").text('<<');
-- VIEW DEMO --
This is because you have wrong selector. According to your markup, .ui-icon
and .ui-icon-circle-triangle-w"
should point to the same <span>
element. So you should use:
$(".ui-icon.ui-icon-circle-triangle-w").html("<<");
or
$(".ui-datepicker-prev .ui-icon").html("<<");
or
$(".ui-datepicker-prev span").html("<<");
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