Home > Mobile >  Get Value From Attribute in JQuery
Get Value From Attribute in JQuery

Time:08-11

I have this attribute element and I want to extract the value from it. I'm not sure how will I do it? I want to extract value from

<select name="Hello/1.0/TestWorld" size="1" disabled="disabled" data-original-title="" title="">
  <option value=""></option>
  <option value="Hello">Hello</option>
 </select>

<script>
$(document).ready(function(){
  const hello = $('qualifier="Hello/1.0/TestWorld"')

  console.log('HELLO', hello)
    });
</script>

CodePudding user response:

$(document).ready(function(){
  const elem = jQuery('[name="Hello/1.0/TestWorld"]');

  console.log(`HELLO: "${elem.val()}"`)
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

<select name="Hello/1.0/TestWorld" size="1" disabled="disabled" data-original-title="" title="">
  <option value=""></option>
  <option value="Hello">Hello</option>
 </select>

CodePudding user response:

You need to access it like this:

    <script>
        $(document).ready(function () {
            const hello = $('.helloDiv attribute');
    
            console.log('HELLO ', hello.attr('qualifier'), hello.attr('editable'));
        });
    </script>
  • Related