0

I would like to get the value of a input using a the a chain class as the identifier in jquery. is this possible?

I have the following code

<input class="donate-block__value monthly" type="text" id="donation-amount" name="DonationAmount" value="200" />

and i have tried the following which has resulted in undefined

var monthlyDonation = $('.donate-block__value .monthly').val();
var monthlyDonation = $('donate-block__value monthly').val();

console.log(monthlyDonation);

I need to target the class Can this be done please?

3 Answers 3

5

Don't add space between your classes or jquery will start to search within the first class looking for a child element. use it like this:

var monthlyDonation = $('.donate-block__value.monthly').val();
Sign up to request clarification or add additional context in comments.

1 Comment

Thats it :)! I cant believe i missed that. Its been a long day. thanks
2

You can also target just the input element in case you have multiple elements with that class defined:

$('input.donate-block__value.monthly').val();

Comments

0

Your selector .donate-block__value .monthly is referring to an element within an element. Try just .donate-block__value or .monthly

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.