Reputation: 804
I am trying to recursively remove all CSS classes from DIVs using jQuery.
this is what I've got so far, but it simply does not work
http://jsfiddle.net/qxy7yotj/4/ (UPDATED)
//UPDATE: another problem is that I have HTML as a JAvascript String and I have to manipulate with it this way
HTML:
<div class="c1">
<div class="c1">
<div class="c3">some text
<div>blah blah</div>
</div>
</div>
</div>
JQuery:
$('div').removeClass();
$('div').each(function( index ) {
$(this).removeClass();
});
Upvotes: 2
Views: 2436
Reputation: 6253
First, create an element on the fly, then search inside it:
var s = '<div class="c1"> <div class="c1"><div class="c3">some text<div>blah blah</div></div></div></div>'
var $elem =
// create on the fly element
$('<div></div>')
// put your string to its content
.html(s)
// find `div` elements
.find('div')
// remove `class` attribute
.removeAttr('class');
$('#id').html($elem.html());
Upvotes: 1
Reputation: 71170
You need to add jQuery to your fiddle, as this is the syntax you are writing your Javascript in.
Then you simply need to use:
$('div').removeAttr('class');
Upvotes: 2