1
$("#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..

4

3 回答 3

4

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.

于 2011-09-14T14:38:55.277 回答
3

You can't have spaces in ID's so you would have to convert it to a dash or something that is valid. someName.Replace(" ","-") is the code to convert the space to a dash.

If this doesn't help then please explain some more. is someName a list of names or is it a single name that needs to be an ID?

于 2011-09-14T14:38:34.727 回答
0

You cannot have spaces in your IDs, but there is a way to select the div anyway.

$("[id='someId_"+someName+"']")

I suggest instead of spaces, you use something else, like an underscore.

<div id="someId_Mohammad_Adil"></div>

Then your $("#someId_"+someName) will work (as long as someName has the spaces converted to underscores: someName = someName.replace(' ', '_');)

于 2011-09-14T14:42:22.720 回答