2

I'm kinda new to Jquery but doing my best to be better.

I have a problem with a variable, so would like to have some help. Have tried and search the web for hours but can't get it to work.

$(document).ready(function() {
    $("a").click(function(){
        var lek = "http://dif.se/wp-content/uploads/2012/03/bortajersey_topp.jpg";
        $(".contact").slideDown();
        var imageurl = $(".contact").text($("img", this).attr("src"));
        $(this).add("img",this).css("background", "yellow");
        $(".contact").append("<img src="+imageurl+">");
    });
});

The variable I have problems with is the imageurl, I get it to work just as I want with the "lek" variable.

Thanks guys, Michael

4

1 に答える 1

1

imageurl contains a jQuery object (since most jQuery calls are chainable). This line:

var imageurl =  $(".contact").text($("img", this).attr("src"));

is effectively equivalent to.:

var imageurl =  $(".contact");
imageurl.text($("img", this).attr("src"));

Try this instead:

var imageurl = $("img", this).attr("src"); // imageurl is a string
$(".contact").text(imageurl);
于 2012-06-10T23:43:13.670 に答える