admin管理员组文章数量:1203388
When you create a Jquery UI accordian you get a bunch of headers, that when you click them a div opens. However, I would like to preform an additional action upon clicking the header.
How do i do this?
Any ideas?
Thanks!
When you create a Jquery UI accordian you get a bunch of headers, that when you click them a div opens. However, I would like to preform an additional action upon clicking the header.
How do i do this?
Any ideas?
Thanks!
Share Improve this question edited Dec 20, 2010 at 19:05 Nick Craver 630k138 gold badges1.3k silver badges1.2k bronze badges asked Dec 20, 2010 at 18:06 kralco626kralco626 8,62441 gold badges115 silver badges171 bronze badges 2- If you have both of the HTML statements provided in the same page, then your HTML is invalid as IDs are suppose to be unique. If not please clarify. – John Hartsock Commented Dec 20, 2010 at 18:09
- No, those were two different attempts. I was making another stupid mistake. I posted the correct answer below. Thanks anyways, sorry. – kralco626 Commented Dec 20, 2010 at 18:10
4 Answers
Reset to default 10Javascript
$("#CreateNewUserHeader").click(function() {
alert("test");
});
html
<h3 id = "CreateNewUserHeader"><a >Create New User</a></h3>
<div>some stuff</div>
You need to wrap your code in ready
handler:
$(function(){
$("#CreateNewUserHeader").click(function() {
alert("test");
});
});
Also make sure that you do not assign same id to more than one elements.
What I've done when I needed to do this in the past was something like this:
$('#accordion h3 a').bind('click', function (e) {
// bind to the the header / anchor clicks
if (!condition) {
e.preventDefault();
e.stopPropagation();
}
});
You guys should read the documentation, there is an event handler that will do it all for you.
https://api.jqueryui.com/accordion/#event-activate
$( ".selector" ).accordion({
activate: function( event, ui ) {}
});
本文标签: javascriptadd click event to Jquery UI accordian HeaderStack Overflow
版权声明:本文标题:javascript - add click event to Jquery UI accordian Header - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738612940a2102736.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论