How do I get a dynamic ID?
I want to access the dynamically generated id in jquery.but, but it doesn't work in jquery, but it does work in javascript.
my jquery code:
var img = $("#MAP"+current_img_height);
$("#map").css({'height': img.height + "px"});
my javascript code:
var img = document.getElementById("MAP" + current_img_height);
$("#map").css({'height': img.height + "px"});
what is wrong in my jquery code and how to get the dynamic id. Any help would be much appreciated
+3
source to share
3 answers
Like your code:
$("#MAP"+current_img_height);
(if current_img_height = 100)
This is the middle $("#MAP100");
* (example: <img id="MAP100">
an item with the given ID "MAP100"
If you want to get the height from an element: do this
var height = $("#whateverID").height();
or
var height = $(".whateverClass").height();
0
source to share