How to change an item without ID in jquery?

HTML codes are as follows:

<div id="select1_chzn" class="chzn-container chzn-container-single" style="width: 250px;"> <a class="chzn-single chzn-single-with-drop" href="javascript:void(0)" tabindex="-1"> <span>AFF5</span> <div></div> </div> 

I was wondering how can I change <span>AFF5</span> to <span>Another</span> in jquery. Anyone have any ideas on this? Thanks!

+6
source share
7 answers

You can use this parent id

 $("#select1_chzn span").text("Another"); 

UPDATE

Using> means a direct descendant, where as space means that the descendant is not necessarily direct.

+12
source

Use CSS selector

 #select1_chzn span 

I'm not a jquery person, but I have seen enough questions here to suggest that you will use

 $('#select1_chzn span') 
+7
source
 $("#select1_chzn span").text("Another"); 

A simple use of the standard CSS descendant selector should be done in this case.

+5
source

parent child , for example:

 $("#select1_chzn span").text('Another'); 
+3
source

The title reads: "How to change an element without ID in jquery?"

If you want to target all span without id in div #select1_chzn , you can do

 $("#select1_chzn span:not([id])").text(...); 

It seems you want the last span :

 $("#select1_chzn span:last").text(...); 
+3
source

You can use any available css selector to select jquery objects, for example, this should work:

 $('span').text('Another'); 
0
source

In fact, you can search for intervals based on their contents if this is the only way to identify them.

 ​$("span:contains(AFF5)").text( "Another" ); 

However, this is case sensitive.

0
source

All Articles