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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:15:37+00:00 2026-06-05T08:15:37+00:00

I’m totally new to jQuery trying to write some scripts to make a navigation

  • 0

I’m totally new to jQuery trying to write some scripts to make a navigation item #printInteract trigger the container border to change colors. It felt like this should work? is this a symantics error? if not could someone maybe explain a bit where I went wrong?

jQuery:

$(document).ready(function(){
var printBorder = $("#container").css("border-color", "blue");
function changeBorder() {printBorder}
$("#printInteract").on("click", changeBorder);

});

CSS
#container{height:95%; position:relative;.clearfix(); border:.1875em #fff solid;}

HTML

 <nav>
    <ul class="navSpaces">
    <li class="navCenter"><a class="navBg" href="#"><div class="relativeCenter"><img src="asset/img/logo30px.png" /><h3>all</h3></div></a></li>
    <li id="printInteract" class="navCenter"><a class="navBg" href="#"><div class="relativeCenter"><img src="asset/img/logo30px.png" /><h3>print</h3></div></a></li>
    <li class="navCenter"><a class="navBg" href="#"><div class="relativeCenter"><img src="asset/img/logo30px.png" /><h3>video</h3></div></a></li>
    <li class="navCenter"><a class="navBg" href="#"><div class="relativeCenter"><img src="asset/img/logo30px.png" /><h3>web</h3></div></a></li>
    </ul>
  </nav>
  • 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-06-05T08:15:38+00:00Added an answer on June 5, 2026 at 8:15 am

    You’re close but slightly off. I’ve commented your code to explain your mistakes.

    $(document).ready(function(){
        //grab the container whose border you want to change
        var container = $("#container");
    
        //when this function is called, change the border
        function changeBorder() {
            container.css({'border' : '1px black solid'});
        }
    
        //watch for the click event and call your function
        $("#printInteract").on("click", changeBorder);
    });
    

    Further, in this case, changeBorder doesn’t doo much. Namely, it only changes the border. For this case, you can just pass an anonymous function rather than define and call a function

    $(document).ready(function(){
        //grab the container whose border you want to change
        var container = $("#container");
    
        //watch for the click event and call your function
        $("#printInteract").on("click", function(){
            //this is the anonymous function. This will only
            // be executed when a click event is triggered
            container.css({'border' : '1px black solid'});
        });
    });
    

    Footnote: You can even skip the part where you grab the jquery object for your container and store it in a variable, since you only reference that object once (while changing borders). However, if you reference that object multiple times, it is considered best practice to ‘cache’ the object in a variable as the code above is doing. This is because every time you request a jQuery object, jQuery has to traverse the DOM looking for all elements that match your selector. Thus, you get marginally better performance by caching the object.

    Edit:

    There is a better way to do what you’re looking for without using 4 click handlers. In fact, you should certainly attempt to minimize the number of event listeners you use in a page since each takes its toll.

    One way to achieve what you’re looking for is to create a Javascript object that serves as a lookup table.

    See the demo here

    This is the Javascript / Jquery code I used:

    //this is the lookup table that maps
    // id with the color scheme
    var borderScheme = {
        'printInteract' : '1px solid blue',
        'videoInteract' : '1px solid orange',
        'webInteract' : '1px solid pink',
        'allInteract' : '1px solid white'
    };
    
    $(document).ready(function(){
        // i am applying border to the entire nav element
        var nav = $('nav');
    
        //we attach a single click listener on li elements
        $('li').on('click',function(){
    
            // get the id of the clicked li
            var id = $(this).attr('id');
    
            // lookup the corresponding border scheme from the lookup table
            var color = borderScheme[id];
    
            // was there a color defined?
            if (color != 'undefined') {
                // if yes, make the change
                nav.css({'border': color});
            }
        });
    });
    
    ​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:

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.