How to change to icon-bar to a new image when clicked via jquary

Started on the old forum in May 2017 · view the original in the archive · old links redirect here

#bootstrap-3 #jquery

2 replies · 58 views · started 9 years ago · 1 min read

2 participants
zervas Junior · 16 posts #1

I'm trying to change the icon-bar class to a new image when a click event happens

Jquery code:

$('#icon_bar_image').click(function(){
       $(this).toggleClass('changeIconBar');  
       });

CSS code:

img.changeIconBar {
background-image: url(../images/collapse_up.png) !important;
width: 50px !important;
height: 50px !important;
}

html code:

<nav class="navbar navbar-inverse">
<div class="container-fluid background-nav">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navigation-bar">
<img src="images/icon_bar_close.png" id="icon_bar_image" width="50" height="50">
</button>

it doesn't work. Does anyone know how I can change an image when a click event happens ?

thank you in advance for your time.

zervas Junior · 16 posts #2

I tried the following code

$('.navbar-toggle').click(function(){

       $("#icon_bar_image").css("background-image","url(../images/collapse_up.png)");

       });

When a user clicks on navbar-toggle then change the image of the icon-bar, but it doesn't work as well. In case you have any ideas , you are welcome to post

morency Senior · 488 posts #3
 
 $('.navbar-toggle').on({     'click': function(){         $('#icon_bar_image').attr('src','collapse_up.jpg');     } }); 

maybe post an jsfiddle here so we can look 🙂

Unamos los corazones,hoy todos somos multicolores!

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close