visibilityattrjquery-3

How to set visibility and attr in jquery 3


After upgrading JQuery 1 to JQuery 3 in our application, some JQuery code stopped working.

I tried looking at https://api.jquery.com/visible-selector/ but could not get help

Previous Code

$("#top_data_label").css("visibility", "visible");

$("#"+element).attr("class", "disable-link").attr("disabled", "disabled");

What changes I need to make in the above code to make it working as per JQuery 3 syntax.


Solution

  • Can you try this :

    $( document ).ready(function() {
        $("#top_data_label").css("visibility", "visible");
    
        $("#"+element).addClass("disable-link");
        $("#"+element).prop("disabled", true);
    });
    

    Do not forget to put the js in on document ready because it will not work if you don't.

    (See jsfiddle which include a document ready)