如何使用JQuery在特定div中获取img

我必须在特定div中获取所有图像标记ID。 我怎样才能使用JQuery?

var arraysOfIds = $('#particularDivId img').map(function(){ return this.id; }).get(); // arraysOfIds has now all the id's, access it as arraysOfIds[0], arraysOfIds[1].... 

粗略猜测,但尝试:

 var imgIds = new Array(); $("div#divID img").each(function(){ imgIds.push($(this).attr('id')); }); 

你没有给出div的名字,但是我使用divId作为div的id。 只需更改它即可满足您的需求。

使用子选择器。 所以你说我想要div #myDiv的所有孩子’img’元素

 $("#myDiv > img").css("border", "3px double red"); 

http://api.jquery.com/child-selector/

 function textOnly() { jQuery('#dvContent img').each(function () { jQuery(this).css('display', 'none'); }); }