Reputation: 851
What are the div tag events in jQuery ? I need to calculate the length of the div for that i wrote these code .
function drop(ev)
{
ev.preventDefault();
var data=ev.dataTransfer.getData("Text");
ev.target.appendChild(document.getElementById(data).cloneNode(true));
var n = $( "#div2" ).length;
alert(n);
}
But every time it showing answer as one . when ever i drop more images it must specify the how many images are in div . Will u help me wwhat event i have to write to get this answer .
Upvotes: 2
Views: 108
Reputation: 148140
To find count
of images in div
you can use descendant selector (“ancestor descendant”)to find descendant of type img
in the div
having id div2
$("#div2 img").length;
Selects all elements that are descendants of a given ancestor, reference.
Upvotes: 1
Reputation: 1007
To get the length of images img tag inside of div i.e div2 :
var len = $("div2 > img").length;
Upvotes: 0
Reputation: 8781
When you use this $( "#div2" )
it means - element with ID="div2". and as you know there could be only 1 such element because id is unique.
For getting all the divs use $( "div" )
for getting all the elements wit div2 class use $( ".div2" )
Upvotes: 0
Reputation: 71918
when ever i drop more images it must specify the how many images are in div
I believe you're looking for
var n = $( "#div2 img" ).length;
Upvotes: 1