Reputation: 47051
The HTML codes are like this:
<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 I could change the <span>AFF5</span>
to <span>Another</span>
in jquery.
Does anyone have ideas about this? Thanks!
Upvotes: 6
Views: 1171
Reputation: 27287
The title says "How to change the element with no ID in jquery?"
If you want to target all span
s with no ID within the div #select1_chzn
, you could do
$("#select1_chzn span:not([id])").text(...);
It seems like you want the last span
:
$("#select1_chzn span:last").text(...);
Upvotes: 3
Reputation: 3655
parent child, like this:
$("#select1_chzn span").text('Another');
Upvotes: 3
Reputation: 5822
You can actually search for spans based on their contents if that is the only way you have of identifying them.
$("span:contains(AFF5)").text( "Another" );
However, this is case sensitive.
Upvotes: 0
Reputation: 1708
Use the CSS selector
#select1_chzn span
I am not jquery person, but I have seen enough questions here on SO to guess that you would use
$('#select1_chzn span')
Upvotes: 7
Reputation: 4211
Could use the id of it parent
$("#select1_chzn span").text("Another");
UPDATE
Using > means direct descendant where as a space means descendant not necessarily direct.
Upvotes: 12
Reputation: 4736
$("#select1_chzn span").text("Another");
Simple use of a standard CSS descendant selector should do in this case.
Upvotes: 5
Reputation: 344
You can use any available css-selector for selecting jquery objects, for example this should work:
$('span').text('Another');
Upvotes: 0