admin管理员组文章数量:1406342
here is relevant code
<div class="call-to-action call-to-action-g1">
<input type="submit" value="Siguiente paso" class="submit">
I can not modify this HTML code . So all I have is this only . The page also has many submit buttons so getelementbyqueryall won't work
here is relevant code
<div class="call-to-action call-to-action-g1">
<input type="submit" value="Siguiente paso" class="submit">
I can not modify this HTML code . So all I have is this only . The page also has many submit buttons so getelementbyqueryall won't work
Share Improve this question edited Dec 3, 2013 at 6:47 Tushar Gupta - curioustushar 57.1k24 gold badges106 silver badges109 bronze badges asked Dec 3, 2013 at 6:47 user1314601user1314601 3-
2
getelementbyqueryall
does not even exist ;) Anyways, only you know the plete HTML. You have to find selector which narrows down the selection as much as possible and then select the correct element, e.g. by index. E.g. if there is only one element that matches.call-to-action input[type=submit]
then you already got it. If there are multiple and yours is the second one, get the second element from the set. – Felix Kling Commented Dec 3, 2013 at 6:48 - Query by type then filter by value? – elclanrs Commented Dec 3, 2013 at 6:49
- relevant code <div class="call-to-action call-to-action-g1"> <input type="submit" value="Siguiente paso" class="submit"> </div> – user1314601 Commented Dec 3, 2013 at 7:02
9 Answers
Reset to default 3You can do this :
$("div.call-to-action.call-to-action-g1 > input[type='submit'].submit[value='Siguiente paso']").on('click',function (){...});
(this is the specific I could find according to your code)
Jquery Solution
$('input[value="Siguiente paso"]').trigger('click');
Javascript Solution
document.querySelectorAll('input[value="Siguiente paso"]').click();
For Older Browsers
function getInputsByValue(value)
{
var allInputs = document.getElementsByTagName("input");
var results = [];
for(var x=0;x<allInputs.length;x++)
if(allInputs[x].value == value)
results.push(allInputs[x]);
return results;
}
The only way I know of, without knowing the index of the item, would be to use getElementsByClassName, and then loop through them all paring the value. If you have two buttons with the same value, pretty sure you're out of options.
Why not use the container elements to reduce the scope of the search
$('.call-to-action-g1 input.submit')....
if you have multiple submit within the container then use the attribute selector along with value
as shown by @Royi
Have you tried using class :
$('.submit').click();
or
$('.submit').trigger( "click" );
fiddle Demo
$('input.submit').filter(function () {
return $.trim(this.value) == 'Siguiente paso';
}).click(function () {
alert('hi');
});
to click
$('input.submit').filter(function () {
return $.trim(this.value) == 'Siguiente paso';
}).click();
Refer to this fiddle You can still capture an event using the type !!
$('input').on("click",function(){
// your code here
});
if you want to refine it even more then you can get the value of clicked element using this.value
and have your code there
$('input').on("click",function(){
alert("Button clicked");
if(this.value=="Siguiente paso"){
alert("Siguiente paso clicked");
}
});
There are many selectors in jquery, not only by id or name. Like this:
$('.submit').click();
also you can see more about the jquery Selector:http://api.jquery./category/selectors/
Try this pure-javascript solution:
document.querySelector(".call-to-action .submit").onclick = function() {
alert('bla bla');
}
本文标签: jqueryHow can I use javascript to quotclickquot a button that has no id or nameStack Overflow
版权声明:本文标题:jquery - How can I use javascript to "click" a button that has no id or name? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745002821a2637084.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论