Graham
Graham

Reputation: 155

Need help converting Jquery to Mootools

Could someone please assist me with converting the following Jquery script to the mootools equivalent?

I need to use Mootools to prevent a conflict issue with my Joomla site.

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery('div.rj_insertcode a.glossarylink').each(function() {
            jQuery(this).replaceWith(jQuery(this).html());
        });  
        jQuery('.no_glossary a.glossarylink').each(function() {
            jQuery(this).replaceWith(jQuery(this).html());
        });  
    });     
    </script>
    </head>

Alternately, it would be appreciated if anyone can recommend how to make the above code compatible with Mootools (I'm fairly new to both languages).

Upvotes: 1

Views: 1175

Answers (2)

Dimitar Christoff
Dimitar Christoff

Reputation: 26165

for mootools 1.2.5

window.addEvent("domready", function(){
    $$('div.rj_insertcode a.glossarylink, .no_glossary a.glossarylink').each(function(el) {
        new Element("span", {
            html: el.get("html")
        }).replaces(el);
    });  
});

for 1.12

window.addEvent("domready", function(){
    $$('div.rj_insertcode a.glossarylink, .no_glossary a.glossarylink').each(function(el) {
        el.replaceWith(new Element("span").setHTML(el.innerHTML));
    });  

notice this really wraps it into a span as you can't just convert an element into ... text });

Upvotes: 2

arian
arian

Reputation: 708

I'm not going to port it over directly, but here are the MooTools equivalents of the used methods:

  • jQuery(document).ready(fn)window.addEvent('domready', fn) - executes the function when the browser is ready loading the DOM - docs
  • jQuery(selector)$$(selector) - returns a collection of elements - docs
  • collection.each(fn)collection.each(fn) - iterates over each element - docs
  • jQuery(this).replaceWith(html)this.replaces(element) - replaces an element with another one - docs

See also the docs which I linked for examples.

Upvotes: 5

Related Questions