I have a button to change page but when I want to click on it with the console it doesn't work. But with the mouse it works.
This is the plunker : http://plnkr.co/edit/shr2xhNHzcYwTBPJlisQ?p=preview
And I do this in the console : $('#language_us').click();
or $('#language_fr').click();
but it doesn't change page.
Have you an idea ? Thanks
You are using anchors <a>
and not button <button>
.
To fire click on <a>
you need to use the DOM element, jQuery object $()
does not work.
Use,
$('#language_us')[0].click();
.trigger()
or .click()
triggers a click handler defined explicitly. You need the native click event which is the default functionality of an anchor. So you need to use HTMLElement Object.
If you would have wrote :
$('#language_fr').click(function(){
alert('..')
})
The
$('#language_fr').click()
would have fired the alert()
.
Try this:
$('#language_us').trigger('click');
$('#language_fr').trigger('click');
Or may be try:
$('#language_us').get(0).click();
$('#language_fr').get(0).click();
也许尝试将标签从改变a
到button
或放一个button
标签里面a
标签并按下。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.