Get ID of element that called a function

前端 未结 7 632
梦毁少年i
梦毁少年i 2020-12-07 20:02

How can I get the ID of an element that called a JS function?

body.jpg is an image of a dog as the user points his/her mouse around the screen at different

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-07 20:22

    i also want this to happen , so just pass the id of the element in the called function and used in my js file :

    function copy(i,n)
    {
     var range = document.createRange();
    range.selectNode(document.getElementById(i));
    window.getSelection().removeAllRanges();
    window.getSelection().addRange(range); 
    document.execCommand('copy');
    window.getSelection().removeAllRanges();
    document.getElementById(n).value = "Copied";
    }
    

提交回复
热议问题