954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

jQuery Create element

In JavaScript (preferably jQuery) how could I create a new element and set its values, but I want it in a specific place In the document.

My divs are structured like this :

/*
container
   item
      [item to be created inserted here]

*/

I know how to do this and insert it before the end body tag, but not like this.
I also say in jQuery, as most of my site is written in jQuery (only the js parts)

Thanks, Matthew.

Matthew N.
Junior Poster
101 posts since Jul 2010
Reputation Points: 10
Solved Threads: 10
 
pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 
$("#item").html()


to replace the inner HTML of #item,

$("#item").before()


to add something before #item,

$("#item").after()


to add something after #item,

$("#item").append()


to add something to the HTML in #item

or just use JavaScript:

document.getElementById('item').innerHTML = "...";
Agarsia
Junior Poster
114 posts since Feb 2011
Reputation Points: 10
Solved Threads: 25
 

Thanks!
Problem solved.

Matthew N.
Junior Poster
101 posts since Jul 2010
Reputation Points: 10
Solved Threads: 10
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: