-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?

cmnardi
  • 1,051
  • 1
  • 13
  • 27
Garima Jain
  • 17
  • 1
  • 5
  • 2
    Note that `cus_control` is not a valid attribute for a `input` element, so your HTML is invalid – Rory McCrossan Aug 31 '16 at 20:43
  • 1
    Possible duplicate of [jQuery access input hidden value](http://stackoverflow.com/questions/4376664/jquery-access-input-hidden-value) – cmnardi Aug 31 '16 at 20:44

3 Answers3

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

adeneo
  • 312,895
  • 29
  • 395
  • 388
0

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

var hiddenElements = $( "body" ).find( ":hidden" )
cmnardi
  • 1,051
  • 1
  • 13
  • 27
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

Garima Jain
  • 17
  • 1
  • 5