ID/Class Selector

前端 未结 5 1062
没有蜡笔的小新
没有蜡笔的小新 2021-01-14 20:32

I have some kind of problem with jQuery selectors.

Let\'s say i want to select $(\'#elementID\') but the elementID is a variable.

5条回答
  •  我在风中等你
    2021-01-14 20:50

    If elementID is a variable ala var elementID = '#someId', I would suggest simply (although I didn't try it ):

    $(elementID)
    

    jQuery/JavaScript should dereference this variable as a string value and wrap the ID correctly for further operations...

提交回复
热议问题