How to get img inside a particular div using JQuer

2019-03-14 15:20发布

I have to get all the image tags ids inside a particular div. How can I get that using JQuery?

4条回答
该账号已被封号
2楼-- · 2019-03-14 15:46

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楼-- · 2019-03-14 15:50
var arraysOfIds = $('#particularDivId img').map(function(){
                       return this.id;
                   }).get();

// arraysOfIds has now all the id's, access it as arraysOfIds[0], arraysOfIds[1]....  
查看更多
4楼-- · 2019-03-14 15:55
function textOnly() {
            jQuery('#dvContent img').each(function () {
                jQuery(this).css('display', 'none');
            });
        }
查看更多
爷、活的狠高调
5楼-- · 2019-03-14 16:08

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/

查看更多
登录 后发表回答