I'm trying to select an id that changes on different posts of same page. So the they have been given an id="show_posts_{PostID}" - on the final output the {PostID} is replaced with a number. In the function I need to call $('show_posts_XXXXXX')
- XXXXXX being the generated ID. I have stored this ID in a variable called postId.
But I can't seem to do this $("'" + "show_posts_" + postId + "'")
Can anyone tell me how I can add a string to the end of a selector?
Should work. If it does, you'll kick yourself. Don't forget the hash for the ID, and the extra quotation marks aren't necessary.
$("#show_posts_" + postId)
You need to include the '#' character at the start of the string.
$('#show_posts_' + postId)
Also, you're trying to stuff the quotes in there in your example, and that doesn't make sense.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With