开发者

Delete attribute with JQuery in IE7

$(myelem).removeAttr('attributeName');

Does not work in IE 7. The suggested workaround is:

$(myelem).prop("attributeName", false);

or

$(myelem).prop("attributeN开发者_高级运维ame", null);

or

$(myelem).attr("attributeName", '');

These are all fine if you want to change the rendering or the behaviour. What I need to is to actually remove the attribute from the source. E.g.

<p align="center"> should become <p> The examples above are focused on doing this <p align=""> Which would change the alignment, but the attribute is still there.

Anyone now a way or really deleting the attribute?

I'm using JQuery 1.6.1


Try replacing the p tag completely, with a new p tag without the attribute:

$(myelem).replaceWith("<p>"+$(myelem).html()+"</p>");


myelem.removeAttribute('attribute name');

This should work, as far as I know the only attributes IE7 is unable to remove are event handlers.

See this link for removeAttribute compatibility.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜