From 8492ba72a98a69d5fa9fb75b81db92c16c94f287 Mon Sep 17 00:00:00 2001 From: Kurtis987 <32711113+Kurtis987@users.noreply.github.com> Date: Sat, 18 Nov 2017 19:10:45 -0500 Subject: [PATCH] Update script.js Remove all of the extra lines of code referring to IDs, and use $(this) to style the h2 that is currently hovered. Remove the style from all of the other h2s using the h2 selector. --- .../events_in_jquery/js/script.js | 68 ++----------------- 1 file changed, 6 insertions(+), 62 deletions(-) diff --git a/Stream-1/Unit19-jquery_events/events_in_jquery/js/script.js b/Stream-1/Unit19-jquery_events/events_in_jquery/js/script.js index 4504e1bc..cf02a7b7 100644 --- a/Stream-1/Unit19-jquery_events/events_in_jquery/js/script.js +++ b/Stream-1/Unit19-jquery_events/events_in_jquery/js/script.js @@ -3,72 +3,16 @@ $(document).ready(function(){ //applies colour red to paragraphs when clicked on $("p").click(function(){ - $("p").addClass( "highlight_text"); + $("p").addClass("highlight_text"); }); - //will add lightblue to h2 elements - $("h2").hover(function(){ - $("h2").addClass( "h2_color"); - }); - - /*this will apply larger font size to the active h2 element + /* this will add lightblue to h2 elements and will apply larger font size to the active h2 element by adding the h2_font_size class but not the other h2 elements by removing class h2_font_size from them*/ - - $("#hr_html").hover(function(){ - $("#hr_mysql").removeClass("h2_font_size"); - $("#hr_python").removeClass("h2_font_size"); - $("#hr_jquery").removeClass("h2_font_size"); - $("#hr_django").removeClass("h2_font_size"); - $("#hr_css").removeClass("h2_font_size"); - $("#hr_mysql").removeClass("h2_font_size"); - $("#hr_html").addClass("h2_font_size"); - - }); - - $("#hr_mysql").hover(function(){ - $("#hr_python").removeClass("h2_font_size"); - $("#hr_jquery").removeClass("h2_font_size"); - $("#hr_django").removeClass("h2_font_size"); - $("#hr_css").removeClass("h2_font_size"); - $("#hr_html").removeClass("h2_font_size"); - $("#hr_mysql").addClass("h2_font_size"); - }); - - $("#hr_python").hover(function(){ - $("#hr_mysql").removeClass("h2_font_size"); - $("#hr_jquery").removeClass("h2_font_size"); - $("#hr_django").removeClass("h2_font_size"); - $("#hr_css").removeClass("h2_font_size"); - $("#hr_html").removeClass("h2_font_size"); - $("#hr_python").addClass("h2_font_size"); - }); - - $("#hr_jquery").hover(function(){ - $("#hr_mysql").removeClass("h2_font_size"); - $("#hr_python").removeClass("h2_font_size"); - $("#hr_django").removeClass("h2_font_size"); - $("#hr_css").removeClass("h2_font_size"); - $("#hr_html").removeClass("h2_font_size"); - $("#hr_jquery").addClass("h2_font_size"); - }); - - $("#hr_django").hover(function(){ - $("#hr_mysql").removeClass("h2_font_size"); - $("#hr_python").removeClass("h2_font_size"); - $("#hr_jquery").removeClass("h2_font_size"); - $("#hr_css").removeClass("h2_font_size"); - $("#hr_html").removeClass("h2_font_size"); - $("#hr_django").addClass("h2_font_size"); - }); - - $("#hr_css").hover(function(){ - $("#hr_mysql").removeClass("h2_font_size"); - $("#hr_python").removeClass("h2_font_size"); - $("#hr_jquery").removeClass("h2_font_size"); - $("#hr_django").removeClass("h2_font_size"); - $("#hr_html").removeClass("h2_font_size"); - $("#hr_css").addClass("h2_font_size"); + $("h2").hover(function(){ + $("h2").addClass("h2_color"); + $("h2").removeClass("h2_font_size"); + $(this).addClass("h2_font_size"); }); //applies colour black to body background when mouse enters over buttons