finding the type of an element using jQuery

前端 未结 3 557
慢半拍i
慢半拍i 2020-11-27 09:38

In jQuery, if I have a reference to an element, how can I determine what kind of element it is, for example, an input or an dropdown? Is there any way to find out?

3条回答
  •  野性不改
    2020-11-27 09:59

    The following will return true if the element is an input:

    $("#elementId").is("input") 
    

    or you can use the following to get the name of the tag:

    $("#elementId").get(0).tagName
    

提交回复
热议问题