Reputation: 2654
I'm sure it's stupidly easy, but how can I replace just the text within an html tag. For instance, from this:
<div style="display: block;">blah blah</div>
<a href="#" style="display: inline; ">(Old text)</a>
to this:
<div style="display: block;">blah blah</div>
<a href="#" style="display: inline; ">(New text)</a>
replace Old text => New text
Many thanks in advance.
Upvotes: 1
Views: 183
Reputation: 70701
First, give your element an ID so you can refer to it:
<a id="something" href="#" style="display: inline; ">(Old text)</a>
Then use the string replace
function:
var str = $('#something').text();
$('#something').text(str.replace('Old text', 'New text'));
Upvotes: 0
Reputation: 3261
Put an id on the element containing the text:
<div style="display: block;">blah blah</div><a href="#" style="display: inline; " id="replaceme">(Old text)</a>
And use
$('#replaceme').html('New text');
This is the basic, I think you can work it out from here :)
Upvotes: 3
Reputation: 100322
Just select the element and change its contents
$("a").html("(New Text)");
References
Upvotes: 3