2

I have an element created dynamically by a razor syntax.I want to select this element from its name and also value attributes. My element is:

<input type="radio" name="4501_LS" value="1" class="icheck " data-radio="iradio_line-blue" data-label="Var" style="position: absolute; opacity: 0;">

actually I tried the code below,

$(('icheck[name=4504_LS]').attr('value') = '1')

but it is probably wrong or unadequate. What am I mising?

1
  • icheck would select an element with that tag/element name. Commented Jan 26, 2016 at 12:34

1 Answer 1

4

If you want to use name and value, you can just use two attribute selectors:

$('[name="4501_LS"][value="1"]')

I would qualify that, as you tried to. You were using a class, so you need to put the . there to make it a class selector:

$('.icheck[name="4501_LS"][value="1"]')

Just a word of warning: The value attribute doesn't change when you change the value of an input; the value attribute defines the default value of an input, which is (of course) its initial value. I figure you're probably not changing the values of those inputs, since they're radio buttons, but I'm just flagging it up for lurkers. When the value of an input is changed (e.g., input.value = x; or $(/*...*/).val(x); or the user changes it if it's a text input or similar), no attribute is changed at all. To change the value attribute, you have to set the defaultValue property (or set the attribute via the DOM's setAttribute or jQuery's attr).

Sign up to request clarification or add additional context in comments.

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.