Hi I have a div with content like this
<div><strong>some content
....</strong></div>
How can I add another element to the div after <strong>
, how to add <span>
element after <strong>
?
Thank you
Hi I have a div with content like this
<div><strong>some content
....</strong></div>
How can I add another element to the div after <strong>
, how to add <span>
element after <strong>
?
Thank you
Just use append
on your div
element:
$('#divId').append('<span>Hi</span>');
It will insert the span
element inside the div
, at the end of the child node list.
Edit: In response to your comment, to remove it, since you added the element with append
, you can get it selecting the last-child:
$("#divId span:last-child").remove();
Or you could remove all the span
elements within the div
:
$("#divId span").remove();
If the <div>
is the only one on the HTML page in question:
$('div strong').after('<span>Span element</span>')