最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Jquery code breaks page Javascript - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question edited Dec 30, 2010 at 3:45 user372551 asked Dec 30, 2010 at 3:25 GrahamGraham 1552 silver badges13 bronze badges 3
  • there might be some other errors happening on the page due to your code which is breaking everything... – kobe Commented Dec 30, 2010 at 3:30
  • Can you post an error from the javascript console? – chaimp Commented Dec 30, 2010 at 3:31
  • what do you mean by "Javascript appears to be disabled or not functioning."? – gianebao Commented Dec 30, 2010 at 3:32
Add a ment  | 

4 Answers 4

Reset to default 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.

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','');
});

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.

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

发布评论

评论列表(0)

  1. 暂无评论