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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:39:26+00:00 2026-05-27T10:39:26+00:00

Given the HTML structure shown below, I’m hoping that if you click on a

  • 0

Given the HTML structure shown below, I’m hoping that if you click on a p in a ul the div.selected next to that ul will have .css("background", "yellow") performed on it.

<ul>
    <li>
        <p>Hello</p>
        <p>Hello</p>
    </li>
</ul>

<div>Hello Again</div>
<div class="selected">Hello Again</div>
<div><span>And Again</span></div>

<ul>
    <li>
        <p>Hello</p>
        <p>Hello</p>
    </li>
</ul>


<div>Hello Again</div>
<div class="selected">Hello Again</div>
<div><span>And Again</span></div>

So far I’ve got;

$("p").next("div .selected").css("background", "yellow");
  • 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-27T10:39:26+00:00Added an answer on May 27, 2026 at 10:39 am

    You’ll need:

    $('ul').on('click', 'p', function () {
        $(this).closest('ul').nextAll('div.selected:first').css('background', 'yellow');
    });
    

    on() was introduced in jQuery 1.7, so if you’re using an older version, try;

    $('ul p').bind('click', function () {
        $(this).closest('ul').nextAll('div.selected:first').css('background', 'yellow');
    });
    

    To add a event handler to a click you need to use an event method. See also the documentation for on(), closest() (to select the first ancestor which matches a selector), nextAll() (which selects the next siblings which matches the selector; as apposed to next() which only considers the next element for selection).

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

Sidebar

Related Questions

Given the following HTML structure: <div id=wrapper> <div id=top> <a href=http://example.com class=link>click here</a> </div>
Given the following HTML structure: <div class=wrapper> <div class=top> <a href=http://example.com class=link>click here</a> </div>
I have a structure that looks like this: http://peterned.home.xs4all.nl/examples/csslayout1.html - where the middle div
I have a necessity to sort a given HTML table of the following structure,
Given the following XML structure <html> <body> <div> <span>Test: Text2</span> </div> <div> <span>Test: Text3</span>
Given the following HTML structure: <div class=wrap> <div id=a></div> <div id=b></div> </div> the following
Two jQuery questions: 1) Given this HTML structure <div id=tipper class=tiplink><a href='test.html' >Link Text</a>
I have a page with the below structure (HTML content shortened for readability), where
Given this structure for a websinte <html> <head> <!-- CSS at the beginning--> <link/>
I have an HTML structure that is being pulled from an RSS feed, and

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.