I have html below. What I want to do depends on some conditions. I want to keep changing the text which is Sometitle
.
<div id="header">
Sometitle
<div>
<div>
aa
</div>
<div>
bb
</div>
</div>
</div>
I tried using Jquery below but it removes the other divs also.
$("#header").text("Its a thrusday today !");
How do I get this done? I cannot modify this HTML in any case. I just have to use jquery and get this thing done.
Here is a jsfiddle I created : http://jsfiddle.net/qYUBp/
const div = document. getElementById('container'); // ✅ Change (replace) the text with HTML div. innerHTML = `<span style="background-color: lime">Replacement HTML</span>`; The innerHTML property gets or sets the HTML contained within the element.
You can force the content of the HTML <div> element stay on the same line by using a little CSS. Use the overflow property, as well as the white-space property set to “nowrap”.
Yes, you can directly add content text into a div tag, although using p tags would be preferable in most circumstances. Save this answer.
If you dont want it in a single line.
var tmp=$("#header>div").html();
$("#header").text("its thursday").append('<div>'+tmp+'</div>');
jsfiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With