Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
180 views
in Technique[技术] by (71.8m points)

javascript - chrome console click function does nothing on a paritcular website

I went to this website

http://getlike.io

and i wanted to do a simple click using the chrome console on that blue button top

enter image description here

I used chrome console and I right clicked on the element > inspect > found element on chromes console > copy selector and I got the selector. Here is the selector for the blue button #header > div.top > div > div > div.col-md-2.col-3 > a

I just add it to a jquery tag since jquery is already loaded $("#header > div.top > div > div > div.col-md-2.col-3 > a").click();

and it does nothing i have tried using javascript as well and still click does nothing..the odd thing is I am always using same way to click with console and it always works but this website..seems like they somehow understand i am performing click action using chrome console? does anyone knows why on this website not possible to click on some elements ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The return value of the Jquery selector is an array. So you have to use the index to point to the item you want to work with.

In this case, because there is only one item with the specified selector, you can use 0 index to access the button in the array.

$("#header > div.top > div > div > div.col-md-2.col-3 > a")[0].click()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...