This doesn't work
var name= "#443.selected:first";
selectedEntity = $(name).attr('entityId');
This works
var name= "li.selected:first";
selectedEntity = $(name).attr('entityId');
selectedEntity
is undefined but an element does exist with id="443" class="selected".
Why doesn't the first example work?
Though in HTML other than HTML5 IDs which start with a number are not allowed, your selector should work ( working Demo ). You must have an error elsewhere in your code and/or markup.
There are several issues you should address:
:first
is useless (and also affected by point 1) entityId
. Instead use the data-
prefix . Then you can use jQuerys data method to get/set those attributes. (Beware however that you cannot use camelCase ).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.