How to bind click event on image added using CSS 'background-image' property in jQuery

后端 未结 4 1317
南旧
南旧 2021-02-04 06:40

Here is my fiddle link

I guess my question is clear by title itself. Still, what I am looking for is an way to bind click event on the image added using css

4条回答
  •  被撕碎了的回忆
    2021-02-04 06:58

    Something like this appears to also work:

    $('.cross').click(function(e) {
      var mousePosInElement = e.pageX - $(this).position().left;
      if (mousePosInElement > $(this).width()) {
         $(this).val(''); 
      }
    });
    

    Link to example

提交回复
热议问题