jquery: width: auto
kullanarak bir öğenin satır içi özelliğini almaya çalışıyorum. Genişliği alır almaz, .width()
, auto
yerine bir px değeri döndürür. Bu neye ihtiyacım örneğidir: Ben setted bu satır içi stili ile bir img
ettikJQuery - Genişlik al: satır içi stilden otomatik
:
<img id='image' style='position: absolute; height: 200px; width: auto; top: 25px; left: 50px;' src='http://tinyurl.com/k8ef66b'/>
Ben görüntü tıklanabilir hale getirmek, bir a
içinde bu görüntüyü kaydırmak gerekir. Ben görüntü stilini almak ve bağlantı etiketi taşımak için de gereklidir: http://jsfiddle.net/cBXAz/1/
bir fikrin:
burada//--- get height, width and entire style
var imgHeight = $("#image").height();
var imgWidth = $("#image").width();
var imgStyle = $("#image").attr("style");
//---remove inline style from the img
$("#image").removeAttr("style");
//--- create the <a>, add the inline style
var anch = $("<a href='#'></a>");
$(anch).attr("style", imgStyle);
//--- add back to the img it's width and height
//--- the problem is here: imgWidth does not contain 'auto'
$("#image").css({"width" : imgWidth, "height" : imgHeight});
//--- wrap the img
$("#image").wrap(anch);
koduyla bir keman var? auto
'u bu satır içi stilden nasıl alabilirim? Görüntüye bir px değeri yerine width: auto
vermem gerekiyor. peşin
sayesinde saygılarımla
'$ ("# resim") css ({ "width": "auto"}) '??? – Morpheus
Kulağa baktığımda görüntüde 'height: auto' görmüyorum. –
@KevinBowersox "width: auto" yazdım, "height" değil :) – BeNdErR