1

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?

4
  • quick note: "overfolow" -> "overflow" Commented Sep 30, 2014 at 17:14
  • javascript.info/tutorial/attributes-and-custom-properties Commented Sep 30, 2014 at 17:15
  • 1
    Avinash Babu i can access custom attribute, but its not my question my question is how to get custom style property. Commented Sep 30, 2014 at 17:18
  • 1
    There is no custom style property. There is just an invalid CSS declaration that is ignored by a browser when it parses a style sheet. Commented Sep 30, 2014 at 17:19

3 Answers 3

1

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;
}
Sign up to request clarification or add additional context in comments.

1 Comment

I was just done it manually like you did. anyways thank you :)
1

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

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

1 Comment

its sends the whole mixed array, mean it treat every single char as array element.
0

check

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

get

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

set

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

delete

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.