How can I match all elements that have a specific attribute that is added at run time?
For example, the code:
$('[onkeydown]')
will successfully match:
<div onkeydown="foo();">
but won't match the following div:
<div id="mydiv">
// ....
<script type="text/javascript">
var element = document.getElementById('mydiv');
element.onkeydown = foo;
</script>
Note: the ID attribute is used as an example. I do not know the ID's attribute values of all the elements I want to match, so please provide a solution which matches all elements that have an attribute specified.
To clarify, in the second example, the following code correctly returns the function that is used:
$('#mydiv').attr('onkeydown') // == foo
Note: if I do the same thing above, but instead of using an event (onkeydown
), I use a different attribute which isn't an event (e.g. title
), it will successfully match the dynamically added attributes. Thus, it seems like it is only a problem with events.