Getting elements that exceed the maxium value JAVASCRIPT JQUERY

0 votes

greetings,

I'm new with java script so bear with me! I want to achieve something using JQuery selectors.

I have a list menu. It looks like this...

<ul style="width:auto">
<li>item one</li>
<li>item two</li>
<li>item three</li>
<li>item four</li>
<li>item five</li>
</ul>

Okay, so currently I'm using the parseInt function to retrieve the integer value of the current width of the ul.

var ul = $("ul");
var currentWidth = parseInt(ul.width);
var maxWidth = 400;

With that giving me the current width I'd like to now create an if statement. This is where it gets really tricky for me.

if(currentWidth <= maxWidth){
alert('great job, do nothing');
}
else {
  // WHAT DO I DO?!
  // I need to take all the elements that makes the ul exceed that maxWidth variable and assign them to a new array called extraItems
}

So how do I get those items. I fear this is so far beyond the basic!

Any help would be so greatly appreciated!

Aug 24, 2022 in Web Development by gaurav
• 23,260 points
469 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Web Development

0 votes
1 answer

How do I handle dynamic DOM elements in jQuery that are added after the initial page load?

To deal with dynamic DOM elements added ...READ MORE

answered Dec 13, 2024 in Web Development by Navya
29 views
0 votes
1 answer

What is the difference between JavaScript and jQuery?

JavaScript is an independent language and can ...READ MORE

answered Jun 27, 2022 in Web Development by rajatha
• 7,680 points
715 views
0 votes
0 answers

Getting the source of this click event in JQuery

I have multiple dynamically created buttons with ...READ MORE

Jul 21, 2022 in Web Development by gaurav
• 23,260 points
1,190 views
0 votes
0 answers

Getting the source of this click event in JQuery

I have multiple dynamically created buttons with ...READ MORE

Jul 22, 2022 in Web Development by gaurav
• 23,260 points
650 views
0 votes
0 answers

Clear an image preview file that was removed from the array with jquery

I tried to figure this out for ...READ MORE

Aug 2, 2022 in Web Development by gaurav
• 23,260 points
917 views
0 votes
0 answers

Getting jQuery selector to recognize newly-added DOM elements

I've searched the jQuery docs and here ...READ MORE

Aug 18, 2022 in Web Development by gaurav
• 23,260 points
1,920 views
0 votes
1 answer

How to use jquery with asp.net ajax?

If you weren't aware, Microsoft is planning ...READ MORE

answered Oct 15, 2018 in IoT (Internet of Things) by Annie97
• 2,160 points
785 views
0 votes
1 answer

Is 'sparkline' a method?

I suggest you to check 2 things That jquery.sparkline.js is actually ...READ MORE

answered Nov 9, 2018 in Apache Spark by Frankie
• 9,830 points
1,351 views
0 votes
1 answer

Count elements in list

Try the following method: len() >>> someList=[] >>> ...READ MORE

answered Nov 24, 2018 in Python by SDeb
• 13,300 points
882 views
0 votes
1 answer

What is jQuery?

Hey, jQuery is a fast and concise JavaScript ...READ MORE

answered Feb 14, 2020 in JQuery by kartik
• 37,520 points
1,410 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP