2

I required a function to remove URLs from <a> divs found within <div class="rj_insertcode">. Not being familiar with with direction to tackle this, I eventually mustered up the following Jquery code:

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

My site uses Joomla CMS and I was able to add the above script to the bottom of the template index.php. It works quite well and removes the links generated between the defined tags.

My problem:
Pages that also include JavaScript do not operate correctly. JavaScript appears to be disabled or not functioning.

What can I change to ensure JavaScript still operates correctly, or is there another method I could adopt?

3
  • there might be some other errors happening on the page due to your code which is breaking everything... Commented Dec 30, 2010 at 3:30
  • Can you post an error from the javascript console? Commented Dec 30, 2010 at 3:31
  • what do you mean by "Javascript appears to be disabled or not functioning."? Commented Dec 30, 2010 at 3:32

4 Answers 4

8

Have you tried using jQuery(... rather than $(... ? That would be a first place to start. I'm not too familiar with Joomla, but I know many CMS's will put jQuery into noConflict mode, and try to keep things happy with any other javascript libraries that might be included.

Sign up to request clarification or add additional context in comments.

Comments

2

Joomla uses Mootools, which does not work with jQuery and would cause your script to break on pages that use Mootools. You can try:

    window.addEvent('domready', function(){
    $$('div.rj_insertcode a').set('href','');
});

4 Comments

It's discussed here, with some solutions: forum.joomla.org/viewtopic.php?t=283215
This sounds quite likely Column.
How would I incorporate this into my index.php file? I am not familiar with MooTools.
The same as the jQuery. Just put it in the template. You would need to make sure Joomla loads mootools on all the pages, which might be a setting. Here is a good place to start (as I am sure that the code I provided wont do exactly what you wanted) mootools.net/docs/core/Element/Element
0

What is the actual problem? Javascript is not being loaded, not executing or not executing correctly? You could use Firebug to get more info and/or paste some page source as it's shown in the browser where the problem is.

Comments

0

Unlike most other modern CMS's such as Expression Engine, Drupal, or WordPress, Joomla loads MooTools in the Joomla head tag rather than jQuery. Using PHP to remove the MooTools can cause third party modules to break.

By default loading jQuery with MooTools causes the page to break. Use MooTools instead and you should be all set.

Cheers, Christopher

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.