Updating the value of data attribute using jQuery

后端 未结 4 2345
长情又很酷
长情又很酷 2020-12-08 18:38

I have the following HTML code:


    \"No\"

        
4条回答
  •  执念已碎
    2020-12-08 19:08

    I want to change the width and height of a div. data attributes did not change it. Instead I use:

    var size = $("#theme_photo_size").val().split("x");
    $("#imageupload_img").width(size[0]);
    $("#imageupload_img").attr("data-width", size[0]);
    $("#imageupload_img").height(size[1]);
    $("#imageupload_img").attr("data-height", size[1]);
    

    be careful:

    $("#imageupload_img").data("height", size[1]); //did not work
    

    did not set it

    $("#imageupload_img").attr("data-height", size[1]); // yes it worked!
    

    this has set it.

提交回复
热议问题