Convert javascript getElementsByName to Jquery
Could anyone please corret me with what I'm doing wrong on scenario below?
I've got bunch of document.getElementById
statement which I would like to convert in to JQuery each
loop. Some reason it'开发者_JAVA技巧s not working, please see my jquery below:
$('.select').each(function () {
$(this).addEventListener('touchstart', function (e) {
e.stopPropagation();
}, false);
});
In nustshell, i'm trying to attach addEventListner
to all the select
elements.
You are selecting elements with a class name of select
.
Drop the .
and it will select select
elements.
Also, you can bind that event with jQuery without having to explicitly iterate over the set.
This is what it should look like...
$('select').bind('touchstart', function(event) {
event.stopPropagation();
});
Remove the period to just target <select>
elements, keep it to target class="select"
精彩评论