1

i have done some code in jquery but where i commented in this bellow code i need to call image src instead of .text can any one help for my question.

$(".open").live('click', function () {
                $("#navMenu").animate({
                    width: "85px"
                }, {
                    queue: false,
                    duration: 500,
                    complete: function () {
                        //$(".open").text("CLOSE");
                        var $this = $(".open");
                        $this.removeClass();
                        $this.addClass("close");
                    }
                });
            });

            $(".close ").live('click', function () {
                $("#navMenu ").animate({
                    width: "52px"
                }, {
                    queue: false,
                    duration: 500,
                    complete: function () {
                        //$(".close").text("OPEN");
                        var $this = $(".close");
                        $this.removeClass();
                        $this.addClass("open");
                    }
                });
            });
        });

4 Answers 4

4

This should give you the src :

var source = $("#myImage").attr("src");
Sign up to request clarification or add additional context in comments.

2 Comments

this below format is not working $(".open").attr("src","images/open_arrow.png");
I will need more context to determine what is going wrong, it might be a good idea to make a new question for this so you can include all the details.
0

Assuming .close is the collection of your images, you can get the src attribute value(s) simply by using:

var src = $('.close').attr('src');

If you want to alter the src attribute:

$('.close').attr('src', 'my new value');

jQuery .attr() API documentation

Comments

0

I'm guessing you are trying to set/change the src attr, to so you can do something like

 $('#image').atrr('src', newSrc);

http://api.jquery.com/attr/

Comments

0

helmus answer is correct for getting the image src value,

If you want to set the src value, you should do like this

$("#myImage").attr("src","http://newimage.com/new.jpg");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.