Add click event in Jquery UI accordian Header

When you create the jQuery user interface, you get a bunch of headers that clicking on them opens a div. However, I would like to perform an additional action after clicking on the title.

How should I do it?

Any ideas?

Thank!

+6
source share
4 answers

Javascript

$("#CreateNewUserHeader").click(function() {
    alert("test");
});

HTML

<h3 id = "CreateNewUserHeader"><a >Create New User</a></h3>
<div>some stuff</div>
+10
source

You need to wrap your code in a handler ready:

$(function(){
  $("#CreateNewUserHeader").click(function() {
    alert("test");
  });
});

Also make sure that you do not assign the same identifier to multiple elements.

+4
source

, , , :

$('#accordion h3 a').bind('click', function (e) {
  // bind to the the header / anchor clicks
  if (!condition) {
    e.preventDefault();
    e.stopPropagation();
  }
});
+3

, , , , .

https://api.jqueryui.com/accordion/#event-activate

$( ".selector" ).accordion({
  activate: function( event, ui ) {}
});
+1

All Articles