PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, July 1, 2022

[FIXED] how to check if element has this value or not

 July 01, 2022     javascript, jquery, shopify     No comments   

Issue

Here is my code i mixed up liquid code and js i got product handle but this if condition is not working i have tag with attribute value still it shows not found can someone help me with this issue

<a class="hidden_wrap" name="hidden_link" data-color="gold" data-stone="tiger-eye" data-handle="copy-of-joory-earrings-tiger-eye-gold
" style="appearance: auto;"> gold-tiger-eye   </a>

<script>
          var handle = "{{product.handle}}";
         if ($(`a[class='hidden_wrap'][data-handle='${handle}').length > 0) {
                    alert("found");
                  }else
                  {

              alert('not found');
          }
</script>
            


Solution

Try With This, Use backtick for product.handle and also for html content in jquery. :)

& Remove White Space after copy-of-joory-earrings-tiger-eye-gold.

<script>
     var handle = `{{product.handle}}`;
     if ($(`a[class='hidden_wrap'][data-handle=${handle}`).length > 0) {
          alert("found");
     }
     else{
          alert('not found');
     }
</script>


Answered By - Darshan Raval
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing