JQUERY Get Element By parameter ID

后端 未结 6 1098
执念已碎
执念已碎 2021-01-20 10:31

just want to know what is the equivalent syntax of this to jquery.

var elm_id = \'my_id\';
var elm = document.getElementById(elm_id);

thank

6条回答
  •  忘掉有多难
    2021-01-20 11:06

    var elm_id = 'my_id'; 
    var elm = $('#' + elm_id)[0];
    

    Adding the [0] gets the actual node which is what document.getElementById(elm_id); returns.

提交回复
热议问题