Search code examples
javascriptprototypejsjavascript-framework

Prototype inner wrap


I have searched the documentation and tried various techniques but have't found a suitable technique to achieve the following dom manipulation:

<h3>hello</h3> 

to

<h3><a href="#">hello</a></h3>

Thanks.


Solution

  • To my knowledge, Prototype has no equivalent to jQuery's wrapInner(). You can, however, simulate it with innerHTML:

    $$("h3").each(function(element) {
        element.replace("<h3><a href='#'>" + element.innerHTML + "</a></h3>");
    });