开发者

Change element tag name Mootools

开发者 https://www.devze.com 2023-04-12 15:57 出处:网络
I am at the end , sooo many posts and Fiddle examples on how to change tag name of all elements on page with Jquery but NONE with moot开发者_JS百科ools. Is there any way to do it? I need to convert al

I am at the end , sooo many posts and Fiddle examples on how to change tag name of all elements on page with Jquery but NONE with moot开发者_JS百科ools. Is there any way to do it? I need to convert all tr to div, not able to change the actual page html, must do it with Moo. Please help.

i have 15 tr's in a div , crazy huh!

<div id="mydiv">
<tr></tr>
<tr></tr>
...
</div>

I need to convert them to divs but keep all attributes and html within tr's in tact. PLEASE help! Thank you!


Replacing elements in mootools is easy, as long as the markup is not invalid as above.

http://jsfiddle.net/dimitar/4WatG/1/

document.getElements("#mydiv span").each(function(el) {
     new Element("div", {
        html: el.get("html")
    }).replaces(el);
});

this will replace all spans for divs in the above markup (use spans instead of trs).

as stated up, http://jsfiddle.net/dimitar/4WatG/ -> firefox strips invalid markup of TR not being a child of a table which makes it hard to target.


I'm just going to leave this floating here.

Element.implement({'swapTagName': function(newTagName) {
    return new Element(newTagName, {html: this.get('html')}).replaces(this);
}});

Usage:

//cleaning HTML3.2 like it's 2012
target.getElements('font[size=5pt],b').swapTagName('h2').addClass('header_paragraphs');
target.getElements('font').swapTagName('p');
0

精彩评论

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