Solved

jQuery change the name

Posted on 2014-10-27
5
111 Views
Last Modified: 2014-10-31
I have the button which is the image when the user click on it I want to change the the button to say click here to close.
$(".contact").click(function () {
    contact()
});

//animation for same page links #
$('a[href*=#]').each(function () {
    //alert('Hello');		
    if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname && this.hash.replace(/#/, '')) {
        var $targetId = $(this.hash),
            $targetAnchor = $('[name=' + this.hash.slice(1) + ']');
        var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
        if ($(this.hash).length) {
            $(this).click(function (event) {
                var targetOffset = $(this.hash).offset();
                var target = this.hash;
                event.preventDefault();
                $('html, body').animate({
                    scrollTop: targetOffset
                }, 500);
                return false;
            });
        }
    }
});

Open in new window

0
Comment
Question by:erikTsomik
  • 3
  • 2
5 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40406720
What is the button (.contact?) and what type of button?
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 40406728
yes the button is in class .contact. The button actually a link  (anchor tag)
0
 
LVL 58

Expert Comment

by:Gary
ID: 40406731
$(".contact").click(function(){contact()});

...becomes...

$(".contact").click(function(){
   $(this).text("Click Here to Close");
    contact();
});
0
 
LVL 19

Author Comment

by:erikTsomik
ID: 40406814
I just want to swap the images. so when they click to open to show the close image

$(this).css('background','url(../images/button_close.png) no-repeat');      

and when close then show open image
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40406821
Two css classes for the two states
a.contact {
    background: url(../images/button_open.png) no-repeat; 
}
a.contact.button-close {
    background: url(../images/button_close.png) no-repeat; 
}

Open in new window


The jQuery
$(".contact").click(function(){
    $(this).toggleClass("button-close");
     contact();
 }); 

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question