javascript - Get CSS styles of an element -


i have element has following styles:

<div id="myelement" style="opacity: 0.9; cursor: auto; visibility: visible;"></div> 

i want make sure (setinterval?) has these styles, no more no less, no changes @ all. wonder if possible retrive styles of element (inline css or external) , compare compare them make sure there not changes?

for single element not imagine performance difference between setting , checking first significant. might this:

$(document).ready(function(){     var t = setinterval(function(){         $('#myelement').attr('style', 'opacity: 0.9; cursor: auto; visibility: visible;');     }, 1000); } 

i realise set styles using $('#myelement').css, want ensure no new styles added, setting style attribute should achieve want. unfortunately doesn't account changes stylesheet or style blocks elsewhere on page. have make style attribute bit more comprehensive , include "!important" after each value.

out of interest, why need this? sounds there might better solution problem.

edit: if want stop user using clearinterval, instead of

var t = setinterval(...); 

just use

setinterval(...); 

as clearinterval requires reference interval in order clear (correct me if i'm wrong here). not creating reference interval still executed not clearable.

ultimately though don't think there fool proof method achieve this. should however, prevent determined users hiding whatever want them see.

edit 2: if want check css possible bit of pain have check each property in turn. using jquery's css function this:

$(document).ready(function(){     setinterval(function(){         var el = $('#myelement');         var tampered = false;         if (el.css('display') != 'block') tampered = true;         if (el.css('visibility') != 'visible') tampered = true;         if (el.css('position') != 'static') tampered = true;         ....         if (tampered){             // thing         }     }, 1000); } 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -