You are here: Reference > JavaScript > client-side > style handling > methods > getStringValue (CSSPrimitiveValue)
getStringValue method (CSSPrimitiveValue)
If the value represented by the current CSSPrimitiveValue object is a string, then retrieves it.
This method can be used if the type of the represented value is CSS_STRING, CSS_URI, CSS_IDENT or CSS_ATTR.
To get the type of the represented value, use the primitiveType property.
Syntax:
You can find the related objects in the Supported by objects section below.
Return value:
String that contains the value.
Example HTML code 1:
This example illustrates the use of the getStringValue method:
|
||||
<head> <script type="text/javascript"> function GetBGImageAsString () { var div = document.getElementById ("myDiv"); if (window.getComputedStyle) { var compStyle = window.getComputedStyle (div, null); try { var value = compStyle.getPropertyCSSValue ("background-image"); var valueType = value.primitiveType; if (CSSPrimitiveValue.CSS_STRING <= valueType && valueType <= CSSPrimitiveValue.CSS_ATTR) { alert ("background-image: " + value.getStringValue ()); } else { alert ("The type of the background-image property is not a string!"); } } catch (e) { alert ("Your browser does not support the getPropertyCSSValue method!"); } } else { alert ("Your browser does not support the getComputedStyle method!"); } } </script> </head> <body> <div id="myDiv" style="background-image:url('picture.gif');">An element with background-image.</div> <br /> <button onclick="GetBGImageAsString ()">Get the value of background-image property as a string!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
Related pages:
External links:
User Contributed Comments