Given i have a sample page that looks like this:
<!DOCTYPE html>
<html>
<body>
<h1 aria-controls="name1">heading</h1>
<p aria-controls="name2">paragraph</p>
<span aria-controls="name1">span</span>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</body>
</html>
How would i use jQuery to select the (2) elements with their aria-controls
attribute set to name1
? (ignoring the fact that the element types are different).
Thank you!
The attribute selector
should work.
Docs: http://api.jquery.com/attribute-equals-selector/
Use something like this -
WORKING DEMO
Above is for if you want to look for elements within a container eg body in this case, it can be some div also.
--OR--
Above is for if you want to get all the elements with this attribute