Reputation: 33956
I want to replace the innerHTML of all divs with class "count" with: items1.innerHTML.
How can I do this?
Upvotes: 12
Views: 36973
Reputation: 1633
you can do this by jQuery this way
$("div.count").html("new content");
Upvotes: 12
Reputation: 185933
Here you go:
var items = document.getElementById( 'items' ),
divs = document.getElementsByClassName( 'count' );
[].slice.call( divs ).forEach(function ( div ) {
div.innerHTML = items.innerHTML;
});
Live demo: http://jsfiddle.net/MGqGe/
I use this [].slice.call( divs )
to transform the NodeList into a regular array, so that I can call the forEach
method on it.
Btw, careful with innerHTML. I personally would use a library (like jQuery) to clone the contents instead.
Upvotes: 21