GibboK GibboK - 1 year ago 71
Javascript Question

Add some text using jQuery

I'm using jQuery, I have a div with H2 tags

<div id="preload"><h2></h2></div>

I would like to know how to use jQuery to add a text within the
<h2> tags

Final result should be:

<div id="preload"><h2>Some text here</h2></div>

I need to add the text without replacing the tags
in the jQuery script.

Any ideas? Many thanks!

Answer Source

Try something like this :

$("div#preload h2").html("Some Text Here")

See the above code in action for your sample HTML here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download