JQuery using a "subquery"

I am sure that the answer has already been given, my problem is that I do not know what to even ask.

I am trying to dynamically add pre-existing HTML separators by cloning them and changing values, and I ran into a problem

HMTL:

<div class="worldRow"> <div class="worldProperties">Name</div> <div class="worldProperties worldName">World name</div> <div class="worldProperties">Population</div> <div class="worldProperties worldPopulation">50</div> <div class="worldProperties">Occupency</div> <div class="worldProperties worldOccupency">45%</div> </div> 

Javascript:

 function addWorld(data){ var row = $('#fakeWorldList .worldRow').clone(); row = $(row).attr('id',data.worldId); $(row).('.worldName').value('this will never work, halp.'); } 

In my javascript, in the last line of my function, I am trying to set a div with class "worldName" to a new value, but I just can't figure out how to do this.

If someone can point me in the right direction, it will be very appreciated.

Greetings

+4
source share
2 answers

You need to use .find () to find the child

 $(row).find('.worldName').text('this will never work, halp.'); 

Example:

 function addWorld(data){ var row = $('#fakeWorldList .worldRow:first').clone(); row = $(row).attr('id',data.worldId); $(row).find('.worldName').text('this will never work, halp.'); } 
+7
source

.value for input elements you need to do

 $(row).find('.worldName').html('this will never work, halp.'); 
0
source

All Articles