jquery: test whether input variable is dom element

前端 未结 4 1929
清歌不尽
清歌不尽 2021-01-02 03:50

I would like to write a jquery function that accepts either a dom element or its id as input:

function myfunction(myinput){
 // pseudocode:
 // if (myinput i         


        
4条回答
  •  太阳男子
    2021-01-02 03:51

    I wonder if a nice ternary would work, something like this

    var myID = $(myInput).attr('id') ? $(myInput).attr('id') : myInput;
    

提交回复
热议问题