Joomla 2.5 Jquery Cannot call method of null

て烟熏妆下的殇ゞ 提交于 2019-12-04 02:38:38

问题


Hi guys I am using Joomla 2.5 with Jquery and I got this strange error in my chrome console:

"Uncaught TypeError: Cannot call method 'slideUp' of null "

here is index.php header section:

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
    <script type="text/javascript" src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/js/jscript.js"></script>
    <jdoc:include type="head" />

and jscript.js code:

$(document).ready(function(){

    var slider = document.getElementById("login-form");

    alert (slider);

    $("#login-form").slideUp(100); <- error is on this line

});

I tested it and alert showed : [object HTMLFormElement], so it meas "login-form" realy exists. can't figure out why am I getting

"Uncaught TypeError: Cannot call method 'slideUp' of null "

Please, can you help me!!!!!!


回答1:


Most probably your jquery code is conflicting with mootools. Try this using

jQuery.noConflict();

Your code will be like below-

var $j = jQuery.noConflict();
$j(document).ready(function(){

    var slider = document.getElementById("login-form");

    alert (slider);

    $j("#login-form").slideUp(100);

});


来源:https://stackoverflow.com/questions/13438464/joomla-2-5-jquery-cannot-call-method-of-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!