开发者

cannot use jquery

开发者 https://www.devze.com 2023-01-05 21:05 出处:网络
i have just started working using jquery. i downloaded jquery \"http://code.jquery.com/jquery-1.4.2.min.js\" from jquery.com..accessed in my html file..

i have just started working using jquery. i downloaded jquery "http://code.jquery.com/jquery-1.4.2.min.js" from jquery.com..accessed in my html file..

<html>
<head>
<title> Jquery fundentals</title>
<script s开发者_如何学运维rc="jquery-1.4.2.min.js" type="text/javascript"></script>
<style type="text/css">
#box{
    background: red;
    width: 300px;
    height: 300px;
}
</style>
<script type="text/javascript">
$(function(){
    $('a').click(function(){
        $('box').fadeOut();
    });
});
</script>
</head>
<body>
    <div id="box"> </div>
    <a href="#"> Click Me! </a>

    </body>
</html>

still cannot see the effect in browser?

also tried "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"...but no use can any one explain the problem? i tried in three browsers. google chrome, mozilla and internet explorer.


 $('box').fadeOut();

needs to be

 $('#box').fadeOut();

because you are talking about the element with ID box. its just like CSS.

As an aside, you might also what to add

return false;

after that line (to prevent the browser following the href attribute of the A you're clicking on which in this case is '#' - which if the page has been scrolled down, would cause it to scroll back to the top)


I think firebug is your best friend form now on :)

First check if jquery is loaded properly. You can do this by using for example this method:

    $(document).ready(function() {
       alert('hi');
    });

Then use some of the selectors from above.


are you using mootools also in your project.If yes then use

var $jq=jQuery.noConflict();

AND then use $jq in place of $.I think its work now.

or u can use this..

$(function(){
    $('a').click(function(){
        $('#box').fadeOut();
    });
});


$('a').click(function(){
    $('#box').fadeOut(); // # means id... 
    return false; // prevent jumping to another page...
});


change your javascript like this:

$(function(){
    $('a').click(function(){
        $('#box').fadeOut();
    });
});

note the # in the second selector. it is used to find elements by id.

Example

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号