I want to redirect users to another page, if the CSS properties on an element do not match.
Currently, this works:
<div id="mydoom">
myDoom
</div>
<style>
#mydoom {
position: relative;
font-size: 25px;
color: red;
visibility: hidden;
display:none;
}
</style>
<script type='text/javascript'>
//<![CDATA[
$(document).ready(function() {
$(function() {
if (
$("#mydoom").css('visibility') == 'hidden' && // See if the visibility is hidden.
$("#mydoom").css('position') == 'relative' && // See if the position relative.
$("#mydoom").css('display') == 'none' && // See if the display is set to none.
$("#mydoom").css('font-size') == '25px' // See if the font-size is 25px.
) {
//do nothing
} else {
window.location.replace("http://example.com");
}
});
})
//]]>
</script>
It worked and redirect the page if I change any of that CSS properties to some other value, if i change position:relative
to position:absolute
then the page redirect to example.
However, when I try to check the padding
property, it doesn't redirect.
For example:
<div id="mydoom">
myDoom
</div>
<style>
#mydoom {
position: relative;
padding: 12px;
color: red;
visibility: hidden;
display:none;
}
</style>
<script type='text/javascript'>
//<![CDATA[
$(document).ready(function() {
$(function() {
if (
$("#mydoom").css('visibility') == 'hidden' && // See if the visibility is hidden.
$("#mydoom").css('position') == 'relative' && // See if the position is relative.
$("#mydoom").css('display') == 'none' && // See if the display is set to none.
$("#mydoom").css('padding') == '5px' // See if padding is 5px.
) {
//do nothing
} else {
window.location.replace("http://example.com");
}
});
})
//]]>
</script>
Now you see, I put padding property and set it to 5px
in JavaScript but write 12px
in CSS, now the page should be redirected but it cannot.
Why does the padding property does not work ?