jquery find img is returning undefined in special case

to describe my case, here's what I have:

javascript code:

$("#tf_zoom").live("click",function() {

    console.log($("#dynam").attr("src"));
}

here I get the value in the first time but after the slider changes the image I get undefined

I also tried:

console.log($(this).find("img").attr("src"));

but this one is not working at all.

html code:

<div id="tf_thumbs" class="tf_thumbs">
            <span id="tf_zoom" class="tf_zoom"></span>
            <img id="dynam" src="http://localhost/mala/assets/uploads/files/c9ab2-1.jpg" alt="Thumb1"/>
        </div>

the problem as I mentioned is that the slider changes the image and modifies the img tag to a new src attribute.

so what should I do.

any help would be greatly appreciated.

Answers


As @Fran├žois Wahl mentioned in his comment that I am using #tf_zoom as a parent for my image tag which is where I went wrong. so, I edited my code to use .tf_thumbs as the parent of my image tag and now it's working.

 $("#tf_zoom").live("click",function() {

    var n = $(".tf_thumbs").find("img").attr("src");
    //var imagespathes = {};
    //console.log($(".tf_thumbs").find("img").attr("src"));
    var modelid = n.substr(43); 


    $.post("models/get_gallery", { "modelid": modelid },
  function(data){
        //console.log(data);
        var imagespathes = $(data).map(function(key, url){
        return({ href: '<?php echo base_url();?>assets/uploads/files/' + url });
      });
      console.log(imagespathes);
  $.fancybox.open(imagespathes);
  }, "json");

            });

Need Your Help

How does the RemoveRange() method work in a List<>?

c# .net list ienumerable

As in title. I know it probably merges 2 sublists before and after deleted items, but how does that method behave when removing LAST elements? In other words: does it somehow make a copy of all ele...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.