开发者

Convert javascript getElementsByName to Jquery

开发者 https://www.devze.com 2023-03-02 18:08 出处:网络
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\'

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"

0

精彩评论

暂无评论...
验证码 换一张
取 消