I need to select a li
element based on a "aria-selected" attribute that is affected to this element after its initialization by a plugin (specifically, it's a JQuery UI tab element, I want to handle the click on "selected" tabs, and those tabs are added to the DOM dynamically) so I would do this :
$("[aria-selected='true']").on('click').method(...);
But I need to attach this handler when the element is created, after which it's too late ; I'm creating the element like this:
var $thisTab = $('<li></li>');
So I need a way to say "attach this handler to this element, but fire it only if it has this attribute, something like:
$thisTab.withClass("[aria-selected='true']").on('click').method(...);
See, this li contains a <a href>link</a>
that is "disabled" by the plugin when the tab is "aria-selected". So I cannot just bind the event and test for the attribute, otherwise I'll break the a link on non-selected tabs ; I hope I'm making sense.
How can I do that?