jQuery: Replace element
Question by Compi | 2012-07-12 at 19:12
I would like to replace a full element of my HTML code with jQuery.
How to exchange the contents of an element, I already know:
var newcontent = 'New Content'; $('#element').empty().append(newcontent);
However, I want, that the entire element with a specific id will be replaced. So, the old element should disappear completely the new one should appear at this point. Is there a way?
Related Topics
How to Replace multiple Texts at the same Time
Tutorial | 0 Comments
jQuery: Does an Element exist?
Tip | 1 Comment
JavaScript and jQuery: Replace content of an element by using innerHTML
Tutorial | 0 Comments
jQuery: Show and hide elements
Tutorial | 0 Comments
jQuery: CSS Stylesheet Switcher
Tutorial | 1 Comment
MySQL: Search and Replace directly in MySQL database
Tip | 1 Comment
jQuery: Count Elements, Images, Classes etc
Tip | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
Yes you can.
Just try using the following code:
With this, you swap the old element with the id "element" to the new element (the HTML code in brackets) completely.
2012-07-13 at 19:27