custom attributes in a script tag

前端 未结 4 671
说谎
说谎 2021-01-18 08:43

Can I use a custom attribute in a script tag such as:



        
4条回答
  •  死守一世寂寞
    2021-01-18 09:43

    You should be able to get it using jquery

    $("script").attr("mycustomattribute");
    

    Or try this using regular JavaScript

    document.getElementsByTagName("script")[0].getAttribute("mycustomattribute");
    

    Might bake sense to give a script tag an id to be able to do this

    document.getElementById("someId").getAttribute("mycustomattribute");
    

提交回复
热议问题