Set text in between

I have this range

<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 span text as << instead of the current Prev text.

I tried this below, but it did not change the text as I expected. How can I do that?

  $(".ui-icon .ui-icon-circle-triangle-w").html('<<'); 
+57
jquery
Nov 21 '12 at 12:11
source share
6 answers

Use .text() instead and change your selector:

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

- VIEW DEMO -

+107
Nov 21 '12 at 12:12
source share

This is because you have the wrong selector. According to your markup, .ui-icon and .ui-icon-circle-triangle-w" should point to the same <span> element. Therefore, you should use:

 $(".ui-icon.ui-icon-circle-triangle-w").html("<<"); 

or

 $(".ui-datepicker-prev .ui-icon").html("<<"); 

or

 $(".ui-datepicker-prev span").html("<<"); 
+11
Nov 21 '12 at 12:12
source share

You need to fix your selector. Although CSS syntax requires the separation of several classes, selector syntax requires that they be directly concatenated and with a dot prefix:

 $(".ui-icon.ui-icon-circle-triangle-w").text(...); 

or better:

 $(".ui-datepicker-prev > span").text(...); 
+4
Nov 21 '12 at 12:13
source share
 $('.ui-icon-circle-triangle-w').text('<<'); 
+3
Nov 21 '12 at 12:13
source share

Give an identifier to your range, and then change the text of the target range.

 $("#StatusTitle").text("Info"); $("#StatusTitleIcon").removeClass("fa-exclamation").addClass("fa-info-circle"); <i id="StatusTitleIcon" class="fa fa-exclamation fa-fw"></i> <span id="StatusTitle">Error</span> 

Here, the text “Error” will become “Info” and their font icons will also be changed.

+1
Nov 04 '13 at 0:14
source share

Give it a try. First, he will look for an anchor tag that contains a span with the class "ui-icon-circle-triangle-w", after which he sets the span text to "<<".

 $('a span.ui-icon-circle-triangle-w').text('<<'); 
+1
Jan 14 '16 at 10:07 on
source share



All Articles