jQuery selectors with variables

前端 未结 5 1141
闹比i
闹比i 2020-11-22 10:24

How to mix variables with selectors?

I have ID variable.

I want to select image with this id from div #one.

jQuery(\'#one img .id\') is

5条回答
  •  我在风中等你
    2020-11-22 10:36

    ID's should be unique in your HTML. So you should be able to select the ID directly without worrying about which DIV it is in. Since you mention the ID is attached to the img tag, then this should be enough.

    $('#' + id);
    

提交回复
热议问题