Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to html text show as par this attribute in jQuery?

The problem is not shown in each tag. I face some issues like this: attr is not a function.

$('document').ready(function() {
  jQuery('.custom-size .size .text').each(function() {
    var option_label = this.attr("option-label");
    jQuery(this).text(option_label);
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<div class="custom-size">
  <div class="size">
    <div class="text" option-label="NONE"></div>
    <div class="text" option-label="44">NONE</div>
    <div class="text" option-label="46">44</div>
    <div class="text" option-label="48">46</div>
  </div>
</div>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

a) Since you are using the latest version of jQuery use $ instead of jQuery

b) You need to use $(this) instead of this.

C) Better to use data-attributes.

Check below:

$('document').ready(function() {
  $('.custom-size .size .text').each(function() {
    var option_label = $(this).data("option-label");
    $(this).text(option_label);
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


<div class="custom-size">
  <div class="size">
    <div class="text" data-option-label="NONE"></div>
    <div class="text" data-option-label="44">NONE</div>
    <div class="text" data-option-label="46">44</div>
    <div class="text" data-option-label="48">46</div>
  </div>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading