Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set the text in a span

Tags:

jquery

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('<<'); 
like image 795
Ayman Hussein Avatar asked Nov 21 '12 12:11

Ayman Hussein


People also ask

How do you set span value?

jQuery: Set a value in a span Set a value in a span using jQuery. JavaScript Code: $(document). ready(function(){ $('#button1').

How would you update the text written inside a span element with?

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.

What is a span in text?

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 .

What is text span in HTML?

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.


2 Answers

Use .text() instead, and change your selector:

$(".ui-datepicker-prev .ui-icon.ui-icon-circle-triangle-w").text('<<'); 

-- VIEW DEMO --

like image 177
Curtis Avatar answered Oct 13 '22 08:10

Curtis


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("<<"); 
like image 44
VisioN Avatar answered Oct 13 '22 10:10

VisioN