开发者

JQuery Function that hides all tags whose functions match a certain pattern

开发者 https://www.devze.com 2023-04-06 23:00 出处:网络
I开发者_如何学Python am new Jquery and have written a toggle function that looks like this: $(\'.one-toggle\').click(function(){

I开发者_如何学Python am new Jquery and have written a toggle function that looks like this:

         $('.one-toggle').click(function(){ 
             $('.one-graph').toggle();
         });

Basically I want to change my two CSS selectors so that they match any tag that has one-toggle and one-graph. I don't want the selector to require a direct match. Regex maybe?


Just use the standard CSS selector separator:

$('.one-toggle, .one-graph').click(function(){ 
     $('.one-graph').toggle();
});


To match tags that have both class names, you just need this:

// cache the selector
var $elements = $('.one-toggle.one-graph').click(function(){ 
    // toggle all matched elements
    $elements.toggle();
    // or did you want to toggle just the clicked element?
    // $(this).toggle();
});
0

精彩评论

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

关注公众号