Reputation: 25
I have html element with some inline styles plus on custom css property. now i can access every style attribute but not my custom style property.
here is my code.
<img id="myimg" class="ImgClass" style="overfolow:hidden;position:absolute;mycustomProp:100;top:15;left:20">
here i cannot get mycustomProp.
Any help?
Upvotes: 1
Views: 1460
Reputation: 3017
check
$("#myDiv").hasAttribute(name)
get
$("#myDiv").getAttribute(name)
set
$("#myDiv").setAttribute(name)
delete
$("#myDiv").removeAttribute(name)
Upvotes: 0
Reputation: 2960
alert(getCustomStyle("myimg","mycustomProp"));
function getCustomStyle(theId,theStyle) {
var styles=document.getElementById(theId).getAttribute("style").split(';');
var astyle;
for(var i=0;i<styles.length;i++) {
astyle=styles[i].split(':');
if(astyle[0]==theStyle) return (astyle[1]);
}
return undefined;
}
Upvotes: 1
Reputation: 2992
document.getElementById("myimg").getAttribute("style")
to retrieve the attribute.
document.getElementById("myimg").setAttribute("style",<string>)
can be used to change it.
Upvotes: 1