javascript how to get html style's custom attribute value

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?

Answers


http://jsfiddle.net/phrjwgxk/

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;
}

document.getElementById("myimg").getAttribute("style") to retrieve the attribute.

document.getElementById("myimg").setAttribute("style",<string>) can be used to change it.


check

$("#myDiv").hasAttribute(name)

get

$("#myDiv").getAttribute(name)

set

$("#myDiv").setAttribute(name)

delete

$("#myDiv").removeAttribute(name)


Need Your Help

ode45 Not Enough Initial Conditions

matlab ode differential-equations

I have defined a function using matlabFunction. Here is the code:

What's the equivalent of this Javascript regexp in PHP?

php javascript html regex forms

I have this js regexp which I need in PHP code now instead: