Grow your CSS skills. Land your dream job.

How to use jQuery to parse all the classes with name/ID of?

  • # October 15, 2008 at 3:57 pm

    I have some dynamic content that gets published in a <span> of ID "giftopt". There can be any number of these <span> tags with ID = "giftopt". Is there a way with jQuery to check the text in ALL the <span></span> tags with ID = "giftopt" until it finds the word I am looking for or doesn’t at all?

    I would like to write a conditional statement that:

    Code:

    My inital test seems that it will check until it comes to the first class with ID "giftopt", but it is highly likely that the first one won’t have the text I am looking forward and I need it to continue to see if there is any other classes with ID = "giftopt".

    Any help?

    # October 15, 2008 at 5:29 pm

    ID’s are UNIQUE, especially when it comes to JavaScript. You’ll need to use a CLASS name of "giftopt" if there are going to multiples on the page that you need to target all as a group.

    # October 16, 2008 at 3:22 pm

    Thats fine.

    So I use a class…

    How do I parse them all to see if any of them contain a certain text?

    # October 16, 2008 at 10:02 pm

    No one knows how?

    pab
    # October 17, 2008 at 12:10 am

    to see if a span contains something you can check with a $(‘span:contains(the word you are looking for)’)

    a simple example would be

    $(document).ready(function() {

    $(‘span:contains(the word you are looking for)’).do what you want from here(”);

    });

    # October 17, 2008 at 7:24 am

    Thanks Pab.

    Is this going to check "ALL" Span’s" tags on the page or just the first one it finds as in my experience (my the cord I included)?

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

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".