Reputation: 25
I want to set display to none of anchor tag using javascript.
i'm using below javascript
<script type="text/javascript">
$(document).ready(function () {
setTimeout(function () {
$("#SwitchToReadingMode-Small14").style.display = 'none';
}, 1000);
});
</script>
but it gives me error Uncaught TypeError: Cannot set property 'display' of undefined.
PLease note that: anchor tag is not in my form. i'm finding that tag and id by pressing F12 button (inspect element). i'm using one embeded code url. on that url this anchor tag is exist
Upvotes: 1
Views: 119
Reputation: 11916
That's because here you use JQuery and not the javascript DOM object
replace:
$("#SwitchToReadingMode-Small14").style.display = 'none';
by:
document.getElementById("SwitchToReadingMode-Small14").style.display = "none";
Upvotes: 1
Reputation: 236022
You're accessing a jQuery object, not a DOM node here. Use
$("#SwitchToReadingMode-Small14")[ 0 ].style.display = 'none';
or (better) just use jQuery
$("#SwitchToReadingMode-Small14").hide();
Upvotes: 1
Reputation: 388316
$("#SwitchToReadingMode-Small14")
returns a jQuery object so it does not have the style
property. Instead you can use the .hide() method provided by jQuery to hide the element
$(document).ready(function () {
setTimeout(function () {
$("#SwitchToReadingMode-Small14").hide();
}, 1000);
});
Upvotes: 1