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 7034745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:13:22+00:00 2026-05-28T01:13:22+00:00

I am using this jQuery code $(‘#share_module:last’).css(background-color,red); but it always does it to the

  • 0

I am using this jQuery code

$('#share_module:last').css("background-color","red");

but it always does it to the first #share_module

The HTML structure goes some what like this

<div id = "share_module" class = "id of the share">
//then stuff inside
</div>
<div id = "share_module" class = "id of the share">
//then stuff inside
</div>
<div id = "share_module" class = "id of the share">
//then stuff inside
</div>
<div id = "share_module" class = "id of the share">
//then stuff inside
</div>
<div id = "share_module" class = "id of the share">
//then stuff inside
</div>

But it just gets the first one. Could anybody 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-28T01:13:23+00:00Added an answer on May 28, 2026 at 1:13 am

    You cannot have multiple DOM elements with the same id. That’s just invalid HTML. Start by fixing your markup and remove this id attribute or at least provide an unique id if you ever expect your script to behave as expected. So if you want to use the :last selector you could use a class selector instead of an id selector for example (it doesn’t make sense to use the :last selector with an id selector because an id selector returns only a single DOM element => as you can have only one element with this id in your DOM => makes sense):

    <div class="share_module" >
        //then stuff inside
    </div>
    <div class="share_module" >
        //then stuff inside
    </div>
    <div class="share_module" >
        //then stuff inside
    </div>
    <div class="share_module" >
        //then stuff inside
    </div>
    <div class="share_module" >
        //then stuff inside
    </div>
    

    and once you have valid markup you can use the :last selector:

    $('.share_module:last').css("background-color","red");
    

    and here’s a live demo.

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

Sidebar

Related Questions

I am using this code: $('.ui-accordion').bind('accordionchange', function(event, ui) { $(this).next().next().css({'background-image':'images/green-bg.jpg'}); //ui.newHeader // jQuery object,
How to make this css code cross browser compatible using jquery. this code only
I'm using this bit of jQuery code to target Safari: if ($.browser.safari) { $('#div1').css({'margin-top':
I'm using this jQuery code for overlay $(a[rel]).overlay({ top: '24%' , mask: { color:
Using this jquery code: <a href=javascript:void(0) id=m1>Get Selected id's</a> jQuery(#m1).click( function() { var s;
I'm using this jquery code to show and hide divs on my page. As
Im using jquery 1.3.2 and this is the code: <script type=text/javascript> //<![CDATA[ jQuery(function(){ jQuery('.news_bullet
i using jquery and jquery-ui, this is my code: <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML
I am using this JQuery Ajax Voting system guide as a rough reference but
I'm using this jQuery inline datePicker plugin sample but I don't know how to

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.