Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

jQuery change the name

Posted on 2014-10-27
5
Medium Priority
?
119 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

715 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