Reputation: 2539
I have a span
tag like this and stored in the variable "foo"
<span class="right margin">
<a href="./?p=filmdetail&fid=644&fileid=722&t=میراث چینی 3D">سی ئی 1500</a>
<br>
Nicole Kidman
</span>
Using jQuery OR javascript, how can I change the "Nicole Kidman" clause with something I want? innerHTML changes everything in the <span>
Edit: I edited the text with this code foo[0].lastChild.nodeValue="something else";
but is there another way doing that using only jQuery?
Upvotes: 0
Views: 139
Reputation: 10663
Here the foo
is not a jQuery object:
foo.lastChild.textContent='something you want'
So the foo
is a jQuery object, but you still need to access the dom element directly:
foo.contents().eq(-1).textContent='something you want'
Upvotes: 1
Reputation: 1157
<span>
is an inline element. We avoid using <br/>
in them.<span>
)I'm not aware of your entire HTML structure so I'm going with what you have posted. Here is a fiddle example for how it can be done.
Upvotes: 1
Reputation: 1634
I recommend you add another span
tag around Nicole Kidman
.
<span class="right margin">
<a href="./?p=filmdetail&fid=644&fileid=722&t=میراث چینی 3D">سی ئی 1500</a>
<br>
<span>Nicole Kidman</span>
</span>
and change the text like this:
$(".right").find("span").text("something you want");
Upvotes: 3