Solved

jQuery change the name

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…

707 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

13 Experts available now in Live!

Get 1:1 Help Now