is it possible to remove a CSS property of an element using JavaScript ?
e.g. I have div.style.zoom = 1.2
,
now i want to remove the zoom property through JavaScript ?
views:
1705answers:
4Typically You cannot remove properties from built-in objects like that, and certainly not in IE (the zoom attribute of the style object is a IE extension)
You can set it to the default value:
el.style.zoom = "";
the effective zoom will now be whatever follows from the definitions set in the stylesheets (through link and style tags)
So this syntax will only modify the local style of this element.
No, there is no generally known way for modifying stylesheets from JavaScript.
However, you can try finding all elements that have this class and setting the "zoom" property to "nothing".
If you are using jQuery javascript library, you can do it with $(".the_required_class").attr("zoom","")
As I understand it, sat wants a function to remove a particular class from an element. Most javascript libraries(JQuery, Prototype, Mootools etc) provide easy to use functions to do it. But the basic idea is simple: One can set & get classes of an element using
ELEMENT.className
If you want to add a new class, do this:
ELEMENT.className += " " + Name_Of_The_Class
If you want to remove a particular class say Name_Of_The_Class from an element then the code will be a little more complex.
var ClassRegEx = new RegExp('(\\s|^)'+Name_Of_The_Class+'(\\s|$)');
if (ELEMENT.className.match(ClassRegEx)) {
ELEMENT.className=ele.className.replace(ClassRegEx,' ');
}
Using jquery (http://jquery.com), one can completely remove an attribute from an element by:
$('div#idOfDiv').removeAttr('class');
Just include the jquery source before you run this line of code. Also, it's best to do that sort of thing after the document has fully loaded, doing so by this exact line:
$(document).ready(function()
{
$('div#idOfDiv').removeAttr('class');
});
, which also have to be included after the jquery source has been included.