DEVOPS
DEVOPS

Reputation: 18790

How to get img inside a particular div using JQuery

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

Upvotes: 18

Views: 74105

Answers (4)

Reigel Gallarde
Reigel Gallarde

Reputation: 65284

var arraysOfIds = $('#particularDivId img').map(function(){
                       return this.id;
                   }).get();

// arraysOfIds has now all the id's, access it as arraysOfIds[0], arraysOfIds[1]....  

Upvotes: 35

Jason Evans
Jason Evans

Reputation: 29186

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.

Upvotes: 10

asd
asd

Reputation:

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

Upvotes: 3

Markive
Markive

Reputation: 2400

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/

Upvotes: 9

Related Questions