Reputation: 155
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
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
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 - docsjQuery(selector)
→ $$(selector)
- returns a collection of elements - docscollection.each(fn)
→ collection.each(fn)
- iterates over each element - docsjQuery(this).replaceWith(html)
→ this.replaces(element)
- replaces an element with another one - docsSee also the docs which I linked for examples.
Upvotes: 5