简体   繁体   English

点击获取元素ID

[英]Get Element ID On Click

I have set up the following function to change the position of the #help Div on load. 我已经设置了以下函数来更改#help Div在加载时的位置。

document.getElementById('help').style.left="600px";

How would I make it work on clicking the #help div? 单击#help div后,如何使它工作? (I tried the following) (我尝试了以下)

$('#help').click()document.getElementById('help').style.left="600px";)

Using plain JavaScript you can set the onclick event with: 使用纯JavaScript,您可以使用以下方法设置onclick事件:

document.getElementById("help").onclick = function() {
    this.style.left = "600px";
}

Using JQuery you can set the click event with click() method: 使用JQuery,可以使用click()方法设置click事件:

$("#help").click(function() {
    this.style.left = "600px";
});
$("#help").click(function () {
    $(this).css({
        left: 600
    });
});

Edit: Wrong copy... My bad... 编辑:错误的复制...我的坏...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM