简体   繁体   中英

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 function (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');

如果“ next”是一个ID,则您需要$(“#next”)。click。您还需要第二个div(假设您有它)。onclick不必要。

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

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

should be

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM