0

This is my html code:

<input type="text" id="home">
<input type"text" id="dog">

I need to do something to read the values in these fields. So I wrote my jquery code:

//this code is wrong because it doesn't work
$('input[type="text"][id="home"] input[type="text"][id="dog"]')....

How I can select something like this? Can anyone help me?

1
  • What do you mean by "doesn't work"? Commented Feb 12, 2016 at 16:23

3 Answers 3

2

For selecting multiple items use comma in between them

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>

    $(document).ready(function () {

        $('#home, #dog').val("hello");
    });
</script>
</head>

<body>

 <input type="text" id="home">
<input type"text" id="dog">
</body>

</html>
Sign up to request clarification or add additional context in comments.

Comments

1

Use a comma between two selectors when you are selecting based on multiple criteria. A simple example is:

$("#element1, #element2, #element3")

Your example:

$('input[type="text"][id="home"], input[type="text"][id="dog"]')

See Multiple Selector (“selector1, selector2, selectorN”)

Comments

1

you should use $('#home, #dog');

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.