开发者

Call hidden div with onclick

I have a div for a button which I want to click and replace the contents on the page with a hidden div. Keep in mind this works without the onclick functi开发者_开发百科on (flashes the first div, then goes straight to 2nd) but when I add onclick it doesn't work.

<div id="next" class="button" name="somename"></div> 

<script>
     $("next").click(function () { 
           $('#div1').fadeOut('medium',function(){$('#div2').fadeIn('medium');}
     });
</script>

The button class has some css properties and an image to be used as a button.


What you're doing is just adding a onclick handler to the div in question. You're not actually triggering that click. For that, you'd need a simple $('#next').click();, or $('#next').trigger('click');


If "next" is an ID then you need $("#next").click You also need a second div (assumed you have it) The onclick should not be necessary.


You are not referencing the div correctly in jQuery- you forgot the # to reference the id.

 $("next").click(function () { ... }

should be

 $("#next").click(function () { ... }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜