I have to get all the image tags ids inside a particular div. How can I get that using JQuery?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
var arraysOfIds = $('#particularDivId img').map(function(){
return this.id;
}).get();
// arraysOfIds has now all the id's, access it as arraysOfIds[0], arraysOfIds[1]....
回答2:
Rough guess, but try:
var imgIds = new Array();
$("div#divID img").each(function(){
imgIds.push($(this).attr('id'));
});
You haven't given the name of the div
, but I've used divId
as the id of the div. Simply change that to suite your needs.
回答3:
Use a child selector. So your saying I want all of the child 'img' elements of div #myDiv
$("#myDiv > img").css("border", "3px double red");
http://api.jquery.com/child-selector/
回答4:
function textOnly() {
jQuery('#dvContent img').each(function () {
jQuery(this).css('display', 'none');
});
}