-3

I have custom attribute tag in my html without id as the number can vary for them

<input type="hidden" cus_control="offer_1" value="123456">
<input type="hidden" cus_control="offer_2" value="1UYREST">

Now I want to read the value of offer_1 and offer_2 which is 123456 and 1UYREST respectively using jquery or javascript. How will I achieve this as I don't have id for them?

2
  • 2
    Note that cus_control is not a valid attribute for a input element, so your HTML is invalid Commented Aug 31, 2016 at 20:43
  • 1
    Possible duplicate of jQuery access input hidden value Commented Aug 31, 2016 at 20:44

3 Answers 3

2

You can target the attribute it self

var value = $('input["cus-control=offer_1"]').val();

Note that you should be using data-attributes, and not invalid custom attributes

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

Comments

0

Try the hidden selector https://api.jquery.com/hidden-selector/

var hiddenElements = $( "body" ).find( ":hidden" )

Comments

0

I finally found a way.

var hiddenElements = $( "body" ).find( "input:hidden" ).not( "script" );
hiddenElements.each(function(){
      if($(this).attr('sfc_control'))
      {
          var control_value = $(this).val();
          var control_name = $(this).attr('cus_control');
      }

    });

Thanks for the suggestions

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.