Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Toggle child element onclick of parent element

$(function(){ 
    $(".dropdown-toggle").click(function(){ 
   $(".arrow").attr('src',  
                ($("img").attr('src') == 'images/icon-arrow-down.svg'  
                    ? 'images/icon-arrow-up.svg'  
                    : 'images/icon-arrow-down.svg' 
                     ) 
                )  
    }); 
}); 
//Here .dropdown-toggle is parent class and .arrow is child class
//This toggles image src on click
//This works if there is one child with .arrow class as im multiple .arrow classes if affects all.
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Toggle #child #element #onclick #parent #element
ADD COMMENT
Topic
Name
3+5 =