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

  • SEARCH
  • Home
  • 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 6149207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:24:50+00:00 2026-05-23T19:24:50+00:00

UPDATE 4: This is what I have at the moment: var $elements = $(‘.dropdown’);

  • 0

UPDATE 4:

This is what I have at the moment:

var $elements = $('.dropdown');
var $lastElement = $elements.last();

$elements.slice(0, -1).each(function() {
    $(this).css('left', $(this).prev.position().left);
});

var $prev = $lastElement.prev();
$lastElement.css('left', $prev.position().left - ($prev.outerWidth() - $lastElement.outerWidth()));

Which is giving me:

Uncaught TypeError: Object function (d,e){var f=c.map(this,b,d);Za.test(a)||(e=d);if(e&&typeof e==="string")f=c.filter(e,f);f=this.length>1?c.unique(f):f;if((this.length>1||ab.test(e))&&$a.test(a))f=f.reverse();return this.pushStack(f,a,bb.call(arguments).join(","))} has no method 'position'
$.ajax.success homepage.htm:138
c.b.extend.each jquery.min.js:33
c.b.fn.b.each jquery.min.js:26
$.ajax.success homepage.htm:137
c.extend.handleSuccess jquery.min.js:142
c.extend.ajax.L.w.onreadystatechange jquery.min.js:141

So something in the above script does not have a position method.


UPDATE 3:

This is what I have at the moment:

var $elements = $(‘.dropdown’);
var $lastElement = $elements.last();

$elements.slice(0, -1).each(function() {
$(this).css(‘left’, $(this).prev.position().left);
});

var $prev = $lastElement.prev();
$lastElement.css(‘left’, $prev.position().left – ($prev.outerWidth() – $lastElement.outerWidth()));

It’s giving me a function required error. When I take out the last 2 lines, the error disappears, but the problem does not get solved.


UPDATE 2:

This is the HTML structure:

<div class="settings"><span id="spanSettings">Settings ▼</span></div>
<div class="dropdown">
    <a href="edit_profile.aspx"><div class="item"><div class="icon" style="background-image: url('http://intranet/img/profile_icon.png');"></div> Edit profile</div></a>
    <a href="manage_tabs.aspx"><div class="item"><div class="icon" style="background-image: url('http://intranet/img/tabs_icon.png');"></div> Tab settings</div></a>
</div>

UPDATE 1:

With: $(this).css('left', $(this).prev().position().left);

I get image 1:

with: $(this).css('right', $(this).prev().position().right);

I get image 2 :

I am after image 3:

^ Image 3 is photoshopped.


ORIGINAL QUESTION:

I have the following script which changes the position of any html element which has the class dropdown

$('.dropdown').each(function() {
    $(this).css('left', $(this).prev().position().left);
});

How do I modify this so it changes all the dropdown‘s to left based on the parent, except the last one, which should be right aligned with the parents right position?

If that is not possible, how do I independently change their positions? instead of using the each function?

  • 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-23T19:24:51+00:00Added an answer on May 23, 2026 at 7:24 pm

    You could do:

    var $elements = $('.dropdown'),
        $lastElement = $elements.last();
    
    $elements.slice(0, -1).each(function() {
        $(this).css('left', $(this).prev().position().left);
    });
    
    $lastElement.css('right', $lastElement.prev().position().right);
    

    Update: to align it as you showed in the picture (I assume it is about the last element), you could try:

    var $prev = $lastElement.prev();
    $lastElement.css('left', $prev.position().left - ($prev.outerWidth() - $lastElement.outerWidth()));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At the moment I have this to check whether the $content is containing youtube
At the moment I have two (maybe more) unordered lists which are sortable with
I have a little trouble understanding scope and lifetime using javaScript and jQuery. I
I have two tables. Report and ReportData . ReportData has a constraint ReportID. How
I have the following code for my google maps app. What I want to
I have been looking at many ASP.Net MVC client side validation ideas including xVal.
I have a LINQ Query that creates a new type that contains a days
I have several web pages with different amount of tables with different amount of
A while ago I needed a script to update some content every week, and
In my code, I have a class that maintains a number of lists. We'll

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.