3

I need to select the element by custom attribute value where the element type should be image. I know the following selectors to get the element

By element type

var imgElms = $("input[type=image]");

By custom attribute

var cusElms = $("input[myAttr='org']");

I need mix of both selector to get all image element that has custom attribute myAttr='org'.

1 Answer 1

5

You'd mix them by simply using both, like this

$("input[type=image][myAttr='org']")

but note that myAttr is not a valid attribute, and you should be using data-attributes instead

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @adeneo, can you please explain how do I use data attribute? Is this predefined attribute with element, actually I have added two three attributes with some element for different purpose.
You just do <div data-myAttr="org"> instead, and same in the selector $("input[type=image][data-myAttr='org']") and it's a valid attribute

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.