开发者

how to identify an html div id which starts with some pattern using jquery

normally we use something like this to identify Id using jquery

 $("#PhotoId").html('some html');

here we get the html (say div) having id 'PhotoId' what if the id is partially dynamic i.e. lets say there are multiple photoes

each id would start with 'PhotoId' E开发者_开发百科X.

 $("#PhotoId" + result.Id).html(some html');

NOW, i want to identify html(div) which starts with 'PhotoId' how can it be done


http://api.jquery.com/attribute-starts-with-selector/

var elements = $('div[id^=PhotoId]');

another approach would be:
give the elements a class, eg. photoId, then you can do something like that

var elements = $('div.photoId');

this would not cause jQuery to parse the id-attributes of the div, instead jQuery would do a simple match on the class


As an alternative to Id you could give each div that you wish to identify a specific class which you could then target using jQuery:

$(".photo").html('some html');


Like this?

$("div[id^=PhotoId]").html(); //take all div with id starting with the word 'PhotoId'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜