Question

I need some help in jquery or javascript. I managed to do the hover effects using...

I need some help in jquery or javascript.

I managed to do the hover effects using css and js but i can't seem to "hold" the hover effects on the default page or even after i clicked on a particular page and landed there.

Am i missing something in my css or js or both?

You can download the working files here together with the instructions + screenshots so that you can better understand what i am trying to describe:
https://www.dropbox.com/s/tige8a9uqay7mcj/WorkingFiles.zip?dl=0

Thanks.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi,

I have just made few changes only in your jquery code. myscript.js file. Pasting the code below.

$(document).ready(function(){

   /*$("#contentNav1").css({
       'font-weight': 'bold',
       'text-decoration': 'underline'});*/
      
   $( "#contentNav1" ).click(function() {
       $( "#contentImg" ).attr( "src", "images/boxImage1.jpg" );
       $( "#contentText" ).html("contentNav Paragraph Text 1<br>contentNav Paragraph Text 1<br>contentNav Paragraph Text 1" );
  
       $.persistHover(this);

   });
   $( "#contentNav2" ).click(function() {
       $( "#contentImg" ).attr( "src", "images/boxImage2.jpg" );
       $( "#contentText" ).html("contentNav Paragraph Text 2<br>contentNav Paragraph Text 2<br>contentNav Paragraph Text 2" );
       $.persistHover(this);  
      
   });
   $( "#contentNav3" ).click(function() {   
       $( "#contentImg" ).attr( "src", "images/boxImage3.jpg" );
       $( "#contentText" ).html("contentNav Paragraph Text 3<br>contentNav Paragraph Text 3<br>contentNav Paragraph Text 3" );
       $.persistHover(this);
          
   });
   $( "#contentNav4" ).click(function() {   
       $( "#contentImg" ).attr( "src", "images/boxImage4.jpg" );
       $( "#contentText" ).html("contentNav Paragraph Text 4<br>contentNav Paragraph Text 4<br>contentNav Paragraph Text 4" );
       $.persistHover(this);  
   });
   $.persistHover = function(element)
{

   $(element).parent().children().css({
       'font-weight': 'normal',
       'text-decoration': 'none'});
$(element).css({
       'font-weight': 'bold',
       'text-decoration': 'underline'});
}
});

Some notes regarding the solution.

1) From your question, I understood that your hover is working fine but you want to persist the hover effects even after you click the link and un-hover.

2)Basically there is no onclick effects in css that would provide you the style changes after you click an element.

3) There is :active selector in css but it's effects will fade away after you click and leave the focus on contentNav elements.

4) I did not know whether you needed the first element "contentNav1" to be bold and underlined on page load. If you need it just uncomment the first callback function ("#contentNav1").css.

5) No changes required in CSS file.

To overcome the challenge, I created a function persistHover in jquery. It takes the element as the parameter i.e. The element in which you are calling the function.

Function works as below.

1) Remove all the effects (bold and underline) of all the children of its parent element . Here in case it will remove all effects of children (li) of its parent (ul).

2)Add bold and underline effect to the element of which onlick event the persistHover function is invoked. For example, if we call onclick of contentNav2 the element contentNav2 is passed through click event function to persisthover function and the css are applied to the element. (While the last clicked element becomes normal).

Add a comment
Know the answer?
Add Answer to:
I need some help in jquery or javascript. I managed to do the hover effects using...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVASCRIPT/JQUERY Hello I would like some help understanding jQuery. Here are the directions: Write a program...

    JAVASCRIPT/JQUERY Hello I would like some help understanding jQuery. Here are the directions: Write a program that creates the following table: Course Course Name Day Time IMS115 Windows 10 Monday 6 PM IMS215 Office 2016 Wednesday 5 PM MIS200 Java Thursday 9 AM MTH105 Business Math Saturday 10 AM Using jQuery, select every other odd row and change the font color to blue and make it bold. And here is my code: Chapter4.html <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="Chapter4.css">...

  • I need help with my javascript project, I've started on it but I can't seem to...

    I need help with my javascript project, I've started on it but I can't seem to get ym java scripts to work with my index.html. Can someone please help me fix my code? I need the main.js & scratchpad.js to work with my index.html .Thank you Directions: Go to the following link: https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/JavaScript_basics On that page, scroll down to "A 'hello world' example". Follow the step-by-step instructions to download their code and edit it in your text editor of choice....

  • I'm having trouble to link the .js file to the html so changes for the html...

    I'm having trouble to link the .js file to the html so changes for the html to be made in the .js file <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>:JavaScript, HTML and jQuery</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <!-- this is so I don't have to give you a separate CSS file --> <style>     .hidden {display: none;}     .menu { width: 100px;} </style> </head> <body> <div class="container"> <h1>Assignment 2: JavaScript, HTML and jQuery</h1> <p>To complete this...

  • This question was answered incorrectly. Please help. I need help using jquery to list 4 links....

    This question was answered incorrectly. Please help. I need help using jquery to list 4 links. They should be labeled part 1 -4. When the link is clicked on, a description should appear under it about the link , followed by the link to the page. Please make all links to hw1.html and all descriptions can just say example. thank you please show output so I know it actually works

  • I am trying to make it so that radio buttons when clicked execute a javascript file....

    I am trying to make it so that radio buttons when clicked execute a javascript file. I have to to have the exercises in external files. Here is what I have so far. I am reusing a script that was used to make radio buttons switch CSS files so I think I have to change the set attribute options. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <p> 4.2 Output: The first 20 Fibonacci numbers, which are...

  • So I need help and I have little time. I was wondering if someone can help...

    So I need help and I have little time. I was wondering if someone can help me out. its due in a few hours and I have been trying to catch up because of persoanl reasons. https://www.dropbox.com/s/95w9wqkova5i8zy/New%20folder.zip?dl=0 those are the folder files, I am bit still behind on Bootstrap. of these SDS for t date. Diss payablo be IO With Its Positions abso, Width ean ute Positions abs a te Wich1 se FIGURE S.39 Completed project 2 PROJECT 3 Art...

  • Assignment:Super Lotto This exercise is JavaScript only. No jQuery, please. Your page should work as follows: Ask the user the highest number that they want to generate. (Some lotteries are 1 ‐ 47, so...

    Assignment:Super Lotto This exercise is JavaScript only. No jQuery, please. Your page should work as follows: Ask the user the highest number that they want to generate. (Some lotteries are 1 ‐ 47, some 1 ‐ 49, etc.) Ask the user how many numbers they want to generate. Create a function that returns a random number between 1 and the highest number (see "Additional Info" below). Create an array of numbers. Run the function the correct number of times, putting...

  • i need help with this homework web page and i need the code too Using the "do while" or the "for" contr...

    i need help with this homework web page and i need the code too Using the "do while" or the "for" control statements, have a visitor to your Web page do, or see, something repeatedly. You could have him or her enter a number of months, an interest-rate, and an amount, and print out a table with the amount on deposit. Try to make the loop appropriate to the website theme that you have picked. Use a function in your...

  • NEED HELP with HTML with Javascript embedding for form validation project below. I have my code...

    NEED HELP with HTML with Javascript embedding for form validation project below. I have my code below but I'm stuck with validation. If anyone can fix it, I'd really appreciate. ****************************************************************************** CODE: <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <title>Nice</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> var textFromTextArea; function getWords(){ var text =...

  • I need HELP to get the code to do these function: If I keep clicking "Generate"...

    I need HELP to get the code to do these function: If I keep clicking "Generate" multiple times, the list keeps on getting bigger. The number of rows should always be equal to the number of columns. Also make the code to show both table at the same time? Here is the code I got some far : Code: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <title>Testing</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous"> </head> <style> td...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT