Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

this seems to be simple.. but I am a bit noobish with jquery, maybe I am doing something silly wrong?

I want to click an image, and on that click, hide another image right next to it.

 <script type="text/javascript"> 

 
        $("#butShowMeSomeUnits").click(function() { 
            $('#arrowUnitspic').hide();
        });
 
      
 </script>

Id's are correct as per the two images. What am I missing? Debugging it, the code never gets fired...

Thanks

EDIT

I had my control as a nested control on an asp masterpage, and its id was being rewritten. I have now fixed the id, but I still cant get any joy... I also see my markup is being rendered as an "input", would that make a difference?

<head>
<script src="js/jquery.min.1.5.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function () {
            $("#butShowMeSomeUnits").click(function () {
                $('#arrowUnitspic').hide();
            });
        });

</script>
</head>

<body>
<input type="image" src="bookings_media/buttons/show-me-some-units.png" onmouseout="this.src='bookings_media/buttons/show-me-some-units.png'" onmouseover="this.src='bookings_media/buttons/show-me-some-units_orange.png'" id="butShowMeSomeUnits" name="ctl00$ctl00$ContentPlaceHolder1$bookings_right_content$butShowMeSomeUnits">
</body>

EDIT JS Fiddle

If there is any confusion... the JS fiddle I spooled up with the exact code also does not work...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
206 views
Welcome To Ask or Share your Answers For Others

1 Answer

You need to do do on page ready:

<script type="text/javascript"> 
$(document).ready(function() {
       $("#butShowMeSomeUnits").click(function() { 
            $('#arrowUnitspic').hide();
        });
});
</script>

Edit: The fiddle you provided did not work until I chose jQuery 1.10.1 from the dropdown. You will notice your onmouseover changes the element first, but once you click on the input it does hide the image. Can you verify this works the same for you?

If the answer is no then I don't think you are loading the jQuery library on your page. To check this should work:

if (typeof jQuery != 'undefined') {

    alert("jQuery library is loaded!");

}else{

    alert("jQuery library is not found!");

}

In addition it might be helpful to see what errors your browser console /dev tools is showing.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...