user1254422
user1254422

Reputation: 193

How to call image src attribute in jquery

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");
                    }
                });
            });
        });

Upvotes: 1

Views: 2736

Answers (4)

Shyju
Shyju

Reputation: 218732

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");

Upvotes: 0

Jack
Jack

Reputation: 10993

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/

Upvotes: 0

KP.
KP.

Reputation: 13730

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

Upvotes: 0

Willem D'Haeseleer
Willem D'Haeseleer

Reputation: 20180

This should give you the src :

var source = $("#myImage").attr("src");

Upvotes: 4

Related Questions