开发者

Extending jQuery's className selector

开发者 https://www.devze.com 2023-02-14 23:19 出处:网络
How can I override $(\".className\") such that if(className=\"xyz\") then开发者_Go百科 alert(\"Hello\")

How can I override $(".className") such that

if(className="xyz") then开发者_Go百科 alert("Hello")

and then do what JQuery is doing.


From what I understand, you want to override/extend the method in jQuery that finds nodes. I can't find any hooks and/or listeners that can be attached to that functionality in the code, so I guess you'll have to modify the source code if you want to achieve this functionality.

I'd suggest adding some sort of event listener interface so you can attach this to arbitrary selectors that fit your needs.


try this :

if($('#selector').hasClass('classname')) alert('Hello')


Is this what you mean?

if ($('div[class="xyz"]').length) {
  alert('Hello');
}
0

精彩评论

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

关注公众号