Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery .attr won't retrieve or change values

I'm trying to change HTML attributes using jQuery, but no matter what I do, I can't get anything to work with jQuery's .attr().

For testing, I've written

alert($("#logo").attr("title"));

and even though I have an img with id="logo" and a title, the alert remains blank.

My full method:

function switchVideo(videoID) {
    var videoPlayer = document.getElementById("example_video_1");
    videoPlayer.src = "video/Occam.webm";
    videoPlayer.load();
    $("#example_video_1").attr("poster", "video/ss.png");

    //Doesn't work:
    alert($("#logo").attr("title"));
    $("#logo").fadeOut();

    videoPlayer.play();
}

My fade out works, so I know I imported jQuery correctly.

I've gotten it working in another document, so there must be something else in the document messing it up. Does anyone know why this simple method won't work?

You can see the source page at http://jrstrauss.net/temp/create.html

like image 714
Russell Strauss Avatar asked Nov 25 '25 11:11

Russell Strauss


2 Answers

Your div has the id logo, not the img. Try:

$("#logo img").attr("title")

like image 70
Ulf Lindback Avatar answered Nov 28 '25 02:11

Ulf Lindback


You should be using $.fn.prop for that now: http://api.jquery.com/prop/

like image 34
Aaron Mc Adam Avatar answered Nov 28 '25 03:11

Aaron Mc Adam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!