Search code examples
javascriptyuiyui3

Select a class which is part name and part variable


I want to select elements with the class .group .level3

Here is what I have now

var level = 3;
Y.all(".group" '.level'+[levelnumber])

That is what I have now but don't know where all the quotation marks should go.

Thanks!!


Solution

  • Remove the square braces

    Also you have some syntax errors with the statement. ".group .level" is a string and you want to concatenate a variable to it

    Y.all(".group" '.level'+[levelnumber])
                 ^ ^      ^ ^           ^
                 ------------------------   Get rid of these
    

    Y.all(".group .level"+ levelnumber)
    

    You generally tend to use [] to access a specific index in Array like objects.