Reputation: 3162
I have this jQuery script:
$('.company').each(function(i, item) {
var tempTitle = item.title;
$('Working').appendTo("div[title='" + tempTitle + "']");
});
and this is the HTML:
<li><div class="company" title="32"></div><div class="shortdescription">Short Description Here</div></li>
<li><div class="company" title="33"></div><div class="shortdescription">Short Description Here</div></li>
<li><div class="company" title="34"></div><div class="shortdescription">Short Description Here</div></li>
<li><div class="company" title="35"></div><div class="shortdescription">Short Description Here</div></li>
<li><div class="company" title="36"></div><div class="shortdescription">Short Description Here</div></li>
and no details are added in the divs.
Where is the mistake I make? O_o
Upvotes: 0
Views: 66
Reputation: 1436
On the basis of keeping it simple - the OP's code looks like it may be machine generated so he can rely on the structure staying the same
So:
$('.company').each(function(i, item) {
$(this).next().append('Working');
});
Would work if that is the case.
or
$(this).next('.shortdescription').append(' Working');
to be safe
Upvotes: 1
Reputation: 40497
appendTo
requires HTML or jQuery wrpped element to append. You are passing simple string working.
Try this:
$('.company').each(function(i, item) {
var tempTitle = item.title;
$('<div>appeded by jQuery</div>').appendTo("div[title='" + tempTitle + "']");
});
Now replace <div>appeded by jQuery</div>
with the HTML you want to append.
Upvotes: 1