tags:

views:

75

answers:

3

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' EX.

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

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

A: 

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');
Andy Rose
+5  A: 

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

Andreas Niedermair
+1 as you get there first.
Andy Rose
each time the result.Id would change how to bind it with...$('div[id^=PhotoId]')ie div id that would start with 'PhotoId' and has dynamic 'result.Id' how to identify this$("#PhotoId" + result.Id)
dexter
do you need the `id` to work with, or just the containers? if you do not need the `id` my solution finishes it. otherwise you'll need some parsing - therefore let me know, and i will expand my answer!
Andreas Niedermair
A: 

Like this?

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