Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a jQuery selector select all elements with an "onclick" attribute?

Basically, I just want to select every node that has the attribute onclick regardless of its value.

I tried this, but it does not work: $('[onlick]')

like image 580
twiz Avatar asked Aug 11 '12 21:08

twiz


2 Answers

If you add a c in the between the n and l in onlick it will work: $('[onclick]')

You can see it working here.

like image 160
Peter Olson Avatar answered Nov 28 '22 08:11

Peter Olson


Try it in an Event Handler in IE9, wont work.

$j(document).ready(function(){
    $j('[onclick]').addClass('turnedOff');
    $j('body').on('click', function(event) {
                           setTimeout(function(event) {
                   $j('[onclick]').removeClass('turnedOff');    
                }, 3000); 
    });
     });

The second $j('[onclick]') fails. I had to create a function that removed the class.

This was part of an effort to turn off onclicks on a page covered up in Asyn Ajax calls. a bad hack to fix bad design. But it did show that the $j('[onclick]') will not work in event handlers in IE9 The

like image 38
Don Fair Avatar answered Nov 28 '22 07:11

Don Fair