Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6049717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:36:29+00:00 2026-05-23T07:36:29+00:00

This is my first jQuery code. I want my ul element with class .topnav

  • 0

This is my first jQuery code. I want my ul element with class “.topnav” to have value of width attribute from the most width attribute li element that it contains. I have code like this and css for li elements display:none:

$(function(){
    $('.topnav').each(function(){
      $(this).attr('width', Math.max($(this).children().each(function(){$(this).attr('width')})))});
   }) 

But it isn’t work. Does someone could help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:36:30+00:00Added an answer on May 23, 2026 at 7:36 am

    Hmm, it’s hard to understand your question. Did you mean, you want your ul’s width to be the same as the widest li? If so, do you want to include the padding/border/margin of the li?

    Instead of using attr(‘width’), use width([value]) or outerWidth([value]) to get/set your width.

    A lot of other mistake in the code, your $(this).children().each does not return the width. Hang on, let me whip something out real quick, plz hold.

    Here you go:

    var maxWidth = Math.max.apply(Math, $('.topnav > li').map(function(){ return $(this).width(); }).get());
    $('.topnav').width(maxWidth);
    

    The map function ‘converts’ the array of li into an array of its width. get converts it into regular Javascript array. Then you apply the function max passing it Math as the scope in the first argument and the array in the second argument.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to show first element that is hidden by jquery. my html code
I want to find the first span element after class counter, in code something
This is my first time attempting to call an ASP.NET page method from jQuery.
Using Dozer to map two objects, I have: /** /* This first class uses
Code first: '''this is main structure of my program''' from twisted.web import http from
This is my first time using JQuery in any of my projects. I have
Here's some sample code that I want to control using jQuery (white button bg
I have this jquery code: <script> $(function() { $( #sortable ).sortable({ stop: function(event, ui)
I made my first jQuery plugin attempt, but I have this problem/bug which I
This may be a very mundane question, but this is the first jQuery plugin

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.