Saturday 11 November 2017

javascript - In jQuery, how do I select an element by its name attribute?

itemprop="text">

I have 3 radio buttons in my web page,
like below:



data-hide="false" data-console="false" data-babel="false">
class="snippet-code">








In
jQuery, I want to get the value of the selected radio button when any of these three are
clicked. In jQuery we have id (#) and class (.) selectors, but what if I want to find a
radio button by its name, as
below?



$("            attribute>").click(function(){});



Please
tell me how to solve this problem.


class="post-text" itemprop="text">
class="normal">Answer



This
should do it, all of this is in the href="http://docs.jquery.com/Selectors/attributeEquals#attributevalue"
rel="noreferrer">documentation, which has a very similar example to
this:



$("input[type='radio'][name='theme']").click(function()
{
var value =
$(this).val();
});



I
should also note you have multiple identical IDs in that snippet. This is invalid HTML.
Use classes to group set of elements, not IDs, as they should be
unique.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...