Js.elementgetstyle (element, style) application example _javascript tips

Source: Internet
Author: User
Note: Gets the specified style element in the style array of the DOM element
Copy Code code as follows:

function Elementgetstyle (element, style) {
var value = null;
if (Element.style) {
Value = Element.style[style];
}
if (!value) {
if (Document.defaultview && document.defaultView.getComputedStyle) {
var css = Document.defaultView.getComputedStyle (element, NULL);
Value = CSS? Css.getpropertyvalue (style): null;
else if (Element.currentstyle) {
Value = Element.currentstyle[style];
}
}


/** DGF necessary?
if (Window.opera && [' left], ' top ', ' right ', ' bottom '].include (style))
if (Element.getstyle (Element, ' position ') = = ' static ') value = ' auto '; */


return value = = ' Auto '? Null:value;
}

Note: The selected DOM element is highlighted in color color 0.2s
Copy Code code as follows:

function Uiwebhighlight (element,color) {
if (!element) {return}
var highlightcolor = "Yellow";
if (color) {HighlightColor = color}
if (Element.originalcolor = = undefined) {//Avoid picking up highlight
Element.originalcolor = Elementgetstyle (element, "Background-color");
}
Elementsetstyle (element, {"BackgroundColor": HighlightColor});
Window.settimeout (function () {
try {
If element is orphan, probably page of it has already gone, so ignore
if (!element.parentnode) {
Return
}
Elementsetstyle (element, {"BackgroundColor": Element.originalcolor});
catch (e) {}//DGF unhighlighting is very dangerous and low priority
}, 200);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.