locked
How to disable an element a RRS feed

  • Question

  • User-14642827 posted

    I have an element <a id="btnSortBy" ... what is the correct way to disable this?

    Tuesday, January 12, 2016 7:49 PM

Answers

  • User61956409 posted

    Hi bthJ6,

    As Mike said, you could use event.preventDefault() method to cancel the default action.

    https://api.jquery.com/event.preventdefault/

    Besides, you could also try to use the following code.

    <a id="btnSortBy" href="a.aspx" onclick="return false;">Hello</a>

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 13, 2016 3:05 AM

All replies

  • User-821857111 posted
    $('#btnSortBy').on('click', function(e){
        e.preventDefault();
    });

    It will still look like a hyperlink and the cursor will turn into a pointer when the user hovers over it, so you might also want to use CSS to restyle the link so that it looks like normal text and the cursor doesn't change when hovering.

    Tuesday, January 12, 2016 8:23 PM
  • User2103319870 posted

    I have an element <a id="btnSortBy" ... what is the correct way to disable this?

    You can also try with the below code as well to disable a href tag

     <a id="btnSortBy" href="javascript: void(0)">Test</a>

    Tuesday, January 12, 2016 9:20 PM
  • User61956409 posted

    Hi bthJ6,

    As Mike said, you could use event.preventDefault() method to cancel the default action.

    https://api.jquery.com/event.preventdefault/

    Besides, you could also try to use the following code.

    <a id="btnSortBy" href="a.aspx" onclick="return false;">Hello</a>

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 13, 2016 3:05 AM
  • User-14642827 posted

    Now that the button is disabled, how do I enable it when the user clicks on an item and puts it in the selection box.

    Wednesday, January 13, 2016 1:20 PM