Search code examples
javascriptjqueryjquery-filter

Dynamic id in jquery


$("#someId_"+someName).css(....);

This is what i am doing to get the div in jquery. This is working just fine except when 'someName' contains String with multiple tokens like "Mohammad Adil"

is there any other way of doing the same thing ?

thanks..


Solution

  • Don't do that. You cannot have spaces in your id.

    Quoting the HTML5 spec(emphasis mine)

    The id attribute specifies its element's unique identifier (ID). The value must be unique amongst all the IDs in the element's home subtree and must contain at least one character. The value must not contain any space characters.