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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:24:40+00:00 2026-05-24T23:24:40+00:00

I want to have it so that clicking one element affects a different one,

  • 0

I want to have it so that clicking one element affects a different one, based on some kind of reference stored in the clicked element. I have the following script, but it doesn’t seem to be running properly:

 $("#elementSelectionList li a").click(function(event) { 
    var targetElement = $(this).attr('href');
    loadEditor($(targetElement));
});

I have even tried with loadEditor($('#tagline')); and it’s still not working.

Here is the HTML

<div id="preview">
     <h1 id="tagline" class="editable">The tagline</h1>
</div>


<div id="elementSelectionList">
     <ul>
           <li><a href="#tagline">Tagline</a></li>
     </ul>
</div>

The functionality I want is the following:

clicking an .editable element makes the #textedit box appear in front of it (that’s working). clicking an item in the elementSelectionList list should make the #textEdit box appear in front of the element with corresponding id to the href.

(edited heavily) and here is a broader swath of code (the js isn’t running proper in the fiddle right now for some reason.. it’s just to give a broader overview)

  • 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-24T23:24:40+00:00Added an answer on May 24, 2026 at 11:24 pm

    It isn’t completely clear on what you are trying to do, but from what I gather, you are trying to change some element with the ID that you retrieving from the href of some menu item. You seem to be doing it basically right, maybe the you are not feeding the loadEditor function you are calling correctly?

    CSS

    .red {
      background : red;
    }
    

    HTML

    <div id="preview">
        <h1 id="tagline" class="editable">The tagline</h1>
        <h1 id="tagline2" class="editable">The tagline2</h1>
        <h1 id="tagline3" class="editable">The tagline3</h1>
    </div>
    
    
    <div id="elementSelectionList">
        <ul>
            <li><a href="#tagline">Tagline</a></li>
            <li><a href="#tagline2">Tagline2</a></li>
            <li><a href="#tagline3">Tagline3</a></li>
        </ul>
    </div>
    

    JS

    $(function() {
        //Set Click event for children with 'a' tags
        $('#elementSelectionList a').click(function() {
    
            //Remove Style
            $('#preview').children('.red').removeClass('red');
    
            //Get Node from HREF
            var node = $(this).attr('href');
    
            //Apply Style
            $(node).addClass('red');
        });
    });
    

    When grabbing the ‘href’ attribute from jQuery, you should be able to pass it directly to the jquery selector as you were doing. Again, check your loadEditor code, as that may be where the issue is.

    EDIT: Ok, so, I reviewed your code and I see what your problems are. You are not using the jquery selector function $() correctly in all instances . You are passing your functions jQuery nodes (i.e. the node that is returned from $(), then trying to get the node of the node (unnecessary and will not work). Once you have that node, you can call all jQuery methods on that node…you do not use the $() on it again inside the function in your case. There are many cases where you are doing this inconsistently. Fixing these errors, should fix your code.

    Ex.

    function doSomething(node) {
    
        //Show the element, apply some CSS class, get Text
        node.show()
            .addClass('class');
    
        var txt = node.text();
    }
    
    function doOther(node) {
    
       //Hide the element, and remove class
       node.removeClass('class')
           .hide();
    }
    
    $(function() {
    
        //Anti-pattern...THIS WILL NOT WORK
        //doOther('#test');
        //doSomething('#test');
    
        //Correct Usage
        doOther($('#test'));
        doSomething($('#test'));
    });
    

    Side Note, if you want your functions to be intelligent to it being a jQuery node, or a element selector, you can do this:

    function doSomething(element) {
    
        if(typeof(element) === 'string') {
            element = $(element);
        }
    
        //Code to handle jQuery node here
    }
    

    Just make sure all your instances are correct, and you should be good to go. All your concepts look correct.

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

Sidebar

Related Questions

I have three images that I want to cycle through when clicking on a
I want to have buttons that kind of act like tabs - they switch
I want to have a element that displays in the multiple selection display style
I want to have a function that will return the reverse of a list
I want to have a map that has a homogeneous key type but heterogeneous
I want to have a route that looks something like: www.abc.com/companyName/Controller/Action/Id However, all the
I want to have a program that reads metadata from an MP3 file. My
I have an Expander that I want to have a ListBox in. When the
I want to have a button that has numbers in the range 0 ...
Let's say that I want to have a table that logs the date 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.