JQuery Function that hides all tags whose functions match a certain pattern
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();
});
精彩评论