JQuery Selector for dynamic id

后端 未结 4 773
你的背包
你的背包 2021-01-06 03:58

I am trying to change the image source in the Jquery



        
4条回答
  •  误落风尘
    2021-01-06 04:33

    ID of the HTML elements should be unique across the page.

    You can try

    //I assume id variable is already assigned the id of the element e.g var id = "";
    
    $("#"+ id).attr("src", '/images/wanted_.png');
    

    If you really want to select an element that has the given id and also the class wanted then try this:

    $("#"+ id + ".wanted ").attr("src", '/images/wanted_.png');
    

提交回复
热议问题