Reputation: 281
I have span with id "bar".which contains tag <h3></h3>
and I want to replace <h3></h3>
with "some string". Here is my html
<span id="bar" >
<h3></h3>
</span>
Output I am expecting as
<span id="bar" >
some string
</span>
Many Thanks..
Upvotes: 0
Views: 1175
Reputation: 1111
try this code,
var someString = "Some String";
$("span#bar:has(h3)").replaceWith(someString);
Upvotes: 1
Reputation: 16440
if your some string
contains html tags use html
, otherwise text
var someString = "Some String";
$("span#bar:has(h3)").text(someString);
Upvotes: 3
Reputation: 6122
var text = $('#bar').html();
text = text.replace("<h3></h3>", "some string");
$('#bar').html(text);
Upvotes: 0
Reputation: 144659
You can use html
method:
$('#bar').html('some string');
If you want to just replace the h3 element, you can use replaceWith
method:
$('#bar h3').replaceWith('some string');
Upvotes: 3