The Lodge is members-only design/dev videos and Office Hours.

Next Office Hours Session: "Implementing an SVG Icon System" Nov 30 - 6:00 PM Eastern

If element has class that contains "word", do something…

  • # December 30, 2009 at 2:06 pm


    This is what I’m trying to achieve:

    When a button is clicked, have jQuery look at it’s class. If it’s class has the word "print" in it, or even starts with "p", do some special animation. If it has a class that contains "video", then do a different animation.

    Here is my code so far:

    $(“#grid li a”).click(function() {
    var buttonClass = $(this).attr(‘class’);
    if (buttonClass == ‘print’) {

    The problem is, that simply saying "==" won’t work, since the button classes in my html are "print01", "print02", etc… which is used for other purposes like knowing which print div to show. So how can I get it to just look for the word "print" instead of having to match the full class name exactly? Thanks!

    # December 31, 2009 at 10:47 am
    var buttonClass = $(this).attr(‘class’);
    if (print.test(buttonClass)) {

    print is a regular expression, see this:

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed