Pass element ID to Javascript function

后端 未结 5 1160
南旧
南旧 2020-12-01 16:37

I have seen many threads related to my question title.

Here is HTML Codes :

5条回答
  •  不思量自难忘°
    2020-12-01 16:38

    The problem for me was as simple as just not knowing Javascript well. I was trying to pass the name of the id using double quotes, when I should have been using single. And it worked fine.

    This worked:

    validateSelectizeDropdown('#PartCondition')
    

    This did not:

    validateSelectizeDropdown("#PartCondition")
    

    And the function:

        function validateSelectizeDropdown(name) {
        if ($(name).val() === "") {
             //do something
        }
    }
    

提交回复
热议问题