Solved

jQuery change the name

Posted on 2014-10-27
5
107 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

910 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now