Udders Udders - 1 year ago 84
jQuery Question

Javascript creating <div> on the fly

I have a a link that looks similar to this

<a href="/home/category/blog/1" id="blog">Blog</a>

As you can the link has an ID of 'blog' what I want to do is to create an div on the fly with the ID from the link that was clicked so if the 'blog' is clicked, then the markup would be

<div id="blog">
<!--some content here-->

Like wise if for instance the news link is clicked then I would like,

<div id="news">
<!--some content here-->

to be created in the markup if this possible? and how Im pretty new to jQuery.

Answer Source

Try this:

    $("#wrapper").append("<div id=" + this.id + "></div>");

Not tested, should work ;) where: #wrapper is parent element, work on all a as you see.

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