Hi everyone ! Does anyone know how to set a new tagName to a tag using Jquery? Let's say i have an HTML document and I want to replace all 'fieldset' width 'div'. Thanks in advance !
You can use the replaceWith or the replaceAll functions to replace elements.
You have to manually place the content from the old element to the new element.
$('fieldset').each(function(object){
var html = this.html();
this.replaceWith('div').html(html)
});
Something like this. The code is not tested.
fs = $("fieldset");
for (i = 0; i < fs.length; i++) {
var that = $(fs[i]);
var fieldsetContent = that.html();
that.replaceWith('<div>'+fieldsetContent+'</div>');
};
or try for overflow this css fix css:
fieldset {
display: table-column;
}
<!–[if IE]>
fieldset {
display: block;
}
Than you can set other styles.
Maybe it's less complicated and more effective to try and solve the root of the problem. I can't imagine that there is something hard-coded into Firefox that causes fieldsets to be cut off. I'm 99% sure this can be helped with some CSS. Maybe there you can find more info, or more on-the-spot help, in Mozilla's forums? Maybe examining fieldsets and divs with firebug, and comparing their settings one by one, helps?
I don't know what kind of environment you're in, but maybe the easiest thing would be to set up a "print view" page that dynamically reads the original HTML page and does a low-level replacement in the source code?
In PHP, it would look like this:
$body = str_replace("<fieldset>", "<div>", $body);
$body = str_replace("</fieldset>", "</div>", $body);
Very low level but could work if the HTML is clean.