tags:

views:

50

answers:

5

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 src="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.

A: 
$('a').click(function(){
    $('#box').fadeOut(); // # means id... 
    return false; // prevent jumping to another page...
});
Reigel
+2  A: 
 $('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)

Mailslut
Confirming - tried this and works.
Piskvor
+1  A: 

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.

zarko.susnjar
A: 

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();
    });
});
Bhanu
hey bhanu, my mistake was that i had not used #, before box!
devang
A: 

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

jigfox
thanks Jens, i changed and it started working..!!
devang
you're welcome. You should upvote and/or accept the answer(s) that helped you to solve your problem
jigfox