Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get specific element in jQuery.each loop

Tags:

jquery

I need to get the div containing the street address within the list. The div has a class called address ( div class="address" )

I cannot use jQuery("#storeList li .address"), because there are other elements I need to acces as well.

I have the following code:

jQuery("#storeList li").each(function() {
  var n = jQuery(this.address).text(); // <- This does not work
  alert(n);
});

How do I access each DIV element of type Address?

like image 594
Steven Avatar asked Aug 09 '09 20:08

Steven


People also ask

How do I target a specific element in jQuery?

The jQuery #id selector uses the id attribute of an HTML tag to find the specific element. An id should be unique within a page, so you should use the #id selector when you want to find a single, unique element.

Can you tell something about jQuery each () method?

The each() method in jQuery specifies a function that runs for every matched element. It is one of the widely used traversing methods in JQuery. Using this method, we can iterate over the DOM elements of the jQuery object and can execute a function for every matched element.

How do I iterate data in jQuery?

each(), which is used to iterate, exclusively, over a jQuery object. The $. each() function can be used to iterate over any collection, whether it is an object or an array. In the case of an array, the callback is passed an array index and a corresponding array value each time.

How do you loop through an element with the same class in jQuery?

Answer: Use the jQuery each() Method You can simply use the jQuery each() method to loop through elements with the same class and perform some action based on the specific condition.


1 Answers

jQuery("#storeList li").each(function() {
  var n = jQuery(this).find(".address").text(); // <- This works
  alert(n);
});
like image 170
Scharrels Avatar answered Nov 08 '22 13:11

Scharrels