Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

jQuery change the name

Posted on 2014-10-27
5
Medium Priority
?
120 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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

916 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