

Using jQuery to get the width of each item in a list
source link: https://www.codesd.com/item/using-jquery-to-get-the-width-of-each-item-in-a-list.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Using jQuery to get the width of each item in a list
I am trying to get the width value of each list item in an element but it keeps returning the object and not the width. This should be really simple but for some reason I must be missing something.
Here is my code:
var listWidth = $('ul li').each(function(){
return $(this).width();
});
console.log(listWidth);
Use the map()
(docs) method instead to return the values to a jQuery object, then the get()
(docs) method to convert it to an Array.
var listWidth = $('ul li').map(function(){
return $(this).width();
}).get();
Or similar, you can use the jQuery.map()
(docs) method, which returns an Array.
var listWidth = $.map($('ul li'),function(val){
return $(val).width();
});
Related Articles
Is it possible to use jQuery to get the width of an element in percentage or in pixels, depending on what the developer specified with CSS?
Suppose I have a set of arbitrary elements, can I use jQuery to set the height of each item to 100px?
How to get the name of each item in a list using lapply ()?
Using jQuery to get the value of the multiple check box and output as a string separated by commas.
Jquery gets the width of an item on the click
How do I add items to a drop-down list, then get the text of each item
print () that prints the contents of each item in your list
Python: Count the instances of each item from a list of lists
Get the index of duplicate items in a list in c #
Get the number of duplicate items in a list
jQuery: get the width of each element and summarize them
Using jquery to get the totals per line and the grand total table
Use jquery to get the descendants of an element that are not children of a container with some CSS class
Use jquery to increase the width of the container by 10 rem
Recommend
-
12
Get the Width of Scrollbar Using JavaScript ...
-
7
Add a class with numbers to each element li, jquery advertisements Add class with numbers to each li elements, jquery. Here...
-
6
If the string is equal to the item in list a, followed by the item in list b advertisements I'd like to make an if statement to detect if a st...
-
8
In depth jQuery each function usage i.e. jQuery for loop [5 ways] Satinder Singh / May 31, 2021 /
-
2
JQuery each: If the item is the first child else advertisements So I'm trying to run an each loop in jQuery that has an if statement to determ...
-
6
Introduction As part of this blog , we will go through a scenario of posting a new Item on a SharePoint Site List with data being provided from C4C Service Ticket , using SAP CPI iFlow .
-
8
[Golang] Get UTF-8 String Width March 23, 2016 Get
-
5
JQuery 计算文本的总宽度(Width) JQuery计算文本宽度的原理是利用html提供的<pre>标签,向dom中动态添加<pre>标签,标签里的内容就是要测试长...
-
7
How to animate div width on mouse hover using jQuery 1587 views 2 years ago jQuery Use the jQuery an...
-
13
How to set the width of a div element dynamically using jQuery 3334 views 2 years ago jQuery Use the JavaSc...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK