Pawan
Pawan

Reputation: 32321

How to append data to a div based on the attribute?

I have a HTML as shown above

<div id="restmenu" class="restMenu">
   <ul>
      <section id="4" addlabel="Office" class="ulseWrap lielement">
         <div class="intit someclassss activeRest ">Office<span id="deleteOffice" class="inDelete"></span><span class="inEdit" title="Modify Address" name="Modify Address"></span></div>
      </section>
   </ul>
</div>

When clicked on lielement , i am getting response from the server and adding this particular lielemnt

Right now i am doing this way .

$("#restmenu").find('#'+locationname).append(ulhtml);

By default this is finding id .

Is it possible to find the addlabel attribute and add data to it ??

Means i need to find out the "Office" and add this data to it .

Upvotes: 0

Views: 59

Answers (2)

Bhushan Kawadkar
Bhushan Kawadkar

Reputation: 28513

Yes, it is possible to append using attribute addlabel

$("#restmenu").find('section[addlabel="Office"]').append(ulhtml);

NOTE - Please make sure that ids must be unique through out the document

EDIT - As OP wants addlabel value dynamic, below is the code

Use some variable to store addlabel value and concatenate it in jQuery selector as shown below -

var locationName = "Office";// location name

$("#restmenu").find('section[addlabel="'+ locationName +'"]').append(ulhtml);

Upvotes: 2

collab-with-tushar-raj
collab-with-tushar-raj

Reputation: 1287

Try this for dynamic locationName :-

$("#restmenu").find('section[addlabel="'+locationName+'"]').append(ulhtml)

Upvotes: 0

Related Questions