I'm trying to find text inside an element whose class is either myClass1 OR myClass2.
var myText = $(this).find('.myClass1:first').text();
This works fine but I am unsure if/how I can check for one of 2 classes (my element will only have one class out of these 2 I mentioned).
Thanks for your help!
Enter a comma between the two classes in your selector.
this will match all elements with class "a" OR class "b"
http://api.jquery.com/class-selector/
You can separate your selectors with commas to generate a list containing all elements with either class (or with both):
Use an if statement and the jQuery hasClass() function:
http://api.jquery.com/hasClass/
It would probably look something like this:
If you want the first one found (but only one) use
If you want the first of each kind (two results) then look at the answer provided by @jelbourn.