javascript - Is it possible to get onclick value by input name in jQuery - Stack Overflow

Is it possible to get on click value by input name in jQuery? I don't have neither class nor id an

Is it possible to get on click value by input name in jQuery? I don't have neither class nor id and I want to get the on click value on name only. As I am doing all this in a software to get data.

<input type="button" name="view" value="Click To View Phone, Mobile &amp; Fax Numbers" onclick="viewphone(71241,'divid71241')">

Is it possible to get on click value by input name in jQuery? I don't have neither class nor id and I want to get the on click value on name only. As I am doing all this in a software to get data.

<input type="button" name="view" value="Click To View Phone, Mobile &amp; Fax Numbers" onclick="viewphone(71241,'divid71241')">
Share Improve this question edited Aug 13, 2016 at 16:36 halfer 20.4k19 gold badges109 silver badges202 bronze badges asked Aug 13, 2016 at 7:13 Hitesh ChauhanHitesh Chauhan 872 gold badges4 silver badges13 bronze badges 1
  • 2 Possible duplicate of How can I select an element by name with jQuery? – Tibrogargan Commented Aug 13, 2016 at 7:16
Add a ment  | 

5 Answers 5

Reset to default 2

try this , it is easy to get onclick value

<html>
<head></head>
<title></title>
<script src="https://ajax.googleapis./ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<body>


<input type="button" name="view" value="Click To View Phone, Mobile &amp; Fax Numbers" onclick="viewphone(71241,'divid71241')" style="border: 0px;">

</body>

<script type="text/javascript">
    
   $(document).ready(function(){
   	$('[name=view]').click(function(){
   		var valueis = $(this).attr('onclick');
   		alert(valueis);
   	});
   });


</script>

</html>

You could use the attribute selector

For example for your element

<input type="button" name="view" value="Click To View Phone, Mobile &amp; Fax Numbers" onclick="viewphone(71241,'divid71241')" style="border: 0px;">

If you just have one element with a unique name:

$("input[name='view']").click(function() {
// function data goes here 
console.log( this.value )
});

If you have multiple elements with the same name you can use the each() method

$("input[name='view']").each(function() {
// function data goes here 
console.log( this.value )
});

Output

Click To View Phone, Mobile & Fax Numbers
// other input values here

If you have multiple elements with the same name but only want the first ones value you can use the .first() method:

$("input[name='view']").first(function() {
// function data goes here 
console.log( this.value )
});

yes use the following

onclick="viewphone(71241,'divid71241',this.value)"

Try this one. I believe you can use attr name to trigger an event.

$('input[name=view]').click(function(){
    // functions here
});

Yes , you can do that by using [attribute] selector .

input[name="view"] 

will select that particular Element.

$('input[name="view"]').click(function(){

});

Here is a reference link : https://api.jquery./attribute-equals-selector/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744140861a4560199.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信