Jquery select all items that have a definable passkey

I want to select all items that have a specific passkey.

I know I can do this: $('[accesskey]') , but it gives me a lot of inputs, hrefs, etc. on the page (most of them have an empty access key).

How can I select only those elements where the access key really matters?

Edit: I found the reason for the empty access keys, was called by some old javascript functions to disable / restore accesskeys over several modal dialogs. Usually you won’t get as many elements with blank keys as sub>

+2
source share
3 answers

With one selector:

 $('[accesskey][accesskey!=""]').foo 

How it works:

 // Has the accesskey attribute defined. [accesskey] // Doesn't have an empty value for the accesskey attribute. [accesskey!=""] 

Together, it selects each element with accesskey attributes and is not empty.

+2
source

You can do it

 $('[accesskey]').filter(function(){ return $(this).prop('accessKey'); }); 

.filter() or, like others, already said that you can use attribute-not-equal-selector

Working example

+1
source

you can use an additional loop

 $("[accesskey]").each(function() { if($(this)).attr('accesskey').length > 0) { // do it } } 

Hope this helps you.

0
source

All Articles