0

I am trying to select element with name with jquery but it giving me error don't know whey.

trying select element with name

  $("input[name=session[username_or_email]]");

trying to select element with index

$("input:eq(1)");

"ncaught DOMException: Failed to execute '$' on 'CommandLineAPI': 'input:eq(1)' is not a valid selector.

VM451:1 Uncaught DOMException: Failed to execute '$' on 'CommandLineAPI': 'input[name=session[username_or_email]]' is not a valid selector. at :1:1

Can you help with that please.

1
  • 2
    Can you post the HTML code, so that we can understand what you are trying? Jul 15, 2018 at 17:01

2 Answers 2

1

Selecting input element by name:

$('input[name="myInputName"]');

Selecting input element by index:

$('input:eq(1)');

In that case the element counter start with 0, so the first input element of the DOM have index 0. Don't forget to include the jQuery library in your code at the bottom of the body tag:

<script type="text/javascript" src="path/to/jquery.js"></script>
<script type="text/javascript">
    $('input[name="myInputName"]').on('click', function() {...});
    $('input:eq(1)').on('click', function() {...});
</script>
0

Syntax for this jQuery( "[attribute='value']" )

  • attribute: An attribute name.

  • value: An attribute value. Can be either a valid identifier or a quoted string.

Ex : $( "input[name='man']" )

Try this hope this helps you !

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.