8

I want get all the accesskeys that are on a button or link. I have the following.

$(":button[accesskey!=''], :a[accesskey!='']").each(function(i) {
 //code
});

You can see it here http://jsfiddle.net/QNPZU/

I thought you could have multiple selectors by separating them using a comma but the above code does not work.

If I do

$(":*[accesskey!='']").each(function(i) {
 //code
});

it will work, but I take it there will be a performance problem if the dom is huge?

3 Answers 3

13

You can code:

$("button[accesskey], a[accesskey]").each(function(i) {
   //code
});
Sign up to request clarification or add additional context in comments.

2 Comments

Are you sure :button is deprecated. It seems to be in the main api
@Karsten :button and :radio and several other selectors were deprecated as of jQuery 1.7 and jQuery developers suddenly removed the deprecation notice. Now I have several answers that say "the x selector is deprecated" which is not true anymore. One of them is this answer. Good call. Thanks.
3

Use a instead of :a:

$(":button[accesskey!=''], a[accesskey!='']").each(function(i) {
 //code
});

Code: http://jsfiddle.net/QNPZU/3/

Comments

0

Check this updated fiddle: http://jsfiddle.net/techfoobar/QNPZU/2/

There were 2 problems with your code.

a. For selecting links and buttons, you need to use a and button and not :a and :button

b. You can select items with an attribute called accesskey simply by using a[accesskey]. you need not use a[accesskey!=""]

2 Comments

Thanks the answer. What does the colon do different?
The ':XYZ' notation is for filtering using runtime properties like :visible, :checked etc.. For selecting all elements of a given tag, simply use the tag name as specified in the API doc (previous comment)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.