How To Edit Or Call This Jquery Function To Work On A Vanilla Javascript Onmouseout?
I need to edit or call this jQuery .click() function to use it as a regular or vanilla JavaScript onmouseout: $('#copystuff').click(function() { var temp = $('
Solution 1:
constmyFunc = () => {
var temp = $("<textarea>");
$("body").append(temp);
var previewHeader = $("#PreviewHeader").text();
varHiddenURLdiv = $("#HiddenURLdiv").text();
var contentTogether = previewHeader + "\n" + HiddenURLdiv;
temp.val(contentTogether).select();
document.execCommand("copy");
$("#thecopiedtext").text(contentTogether);
temp.remove();
}
$("#copystuff").click(myFunc).mouseout(myFunc);
Edit
constmyFunc = () => {
var temp = $("<textarea>");
$("body").append(temp);
var previewHeader = $("#PreviewHeader").text();
varHiddenURLdiv = $("#HiddenURLdiv").text();
var contentTogether = previewHeader + "\n" + HiddenURLdiv;
temp.val(contentTogether).select();
document.execCommand("copy");
$("#thecopiedtext").text(contentTogether);
temp.remove();
}
$("#copystuff").click(myFunc);
document.getElementById('copystuff').onmouseout = function(){
this.click()
};
Solution 2:
I would simulate onClick event on it like this:
document.querySelector("your element here").click()
Try using it like this:
Element 1 is the element that has mouseout (mouseleave) event, and element 2 is the element that you want to be clicked, the one that calls what you need.
document.querySelector("element 1").addEventListener("mouseleave", ()=>{
document.querySelector("element 2").click();
});
You can even try changing "mouseleave" with "mouseout"
Implementing my solution with your code:
document.querySelector("you put some element here that you want to add mouseleave event to").addEventListener("mouseleave", ()=>{
document.querySelector("#copystuff").click();
});
Post a Comment for "How To Edit Or Call This Jquery Function To Work On A Vanilla Javascript Onmouseout?"