1

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

3 Answers 3

1

$("#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);
});
Sign up to request clarification or add additional context in comments.

Comments

1

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();

1 Comment

i try this. not giving any error. but also not worked. it is not hiding anchor element
1

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";

1 Comment

also try this code.it gives error uncaught type error cannot read property 'style' of null

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.