Ok, so i have a HTML structure like this:
<div class="content">
<div id="a1" class="article">
<p>content</p>
<p>content</p>
<p class="info"></p>
</div>
<div id="a2" class="article"></div>
<div id="a3" class="article"></div>
<div id="a4" class="article"></div>
</div>
The goal is to process each article and add info about it into the info p element. So I figured I'd loop through all the divs like this:
$$('.article').each(function(item,index){
var info = $(item).select('p.info');
info.updat开发者_开发知识库e('<a>link</a> <p>Stuff about the article etc.</p>');
});
and write new content with update(). It does not work, however, the error being that .update() is not a function. How would I do the update?
OK, results: T.J. Crowder hinted why it wasn't working, and I eventually came up with this code:
$(item).select('p.info')[0].update('Stuff about the article etc.');
Key point was in manipulating the first item of array returned by the select(), which then updated the info element as i wanted it to..
Element#select
returns an array, not an element, but you're treating it like an element. You might want Element#down
instead.
精彩评论