echo-ed HTML Element from PHP is not read in JAVASCRIPT -


so have html elements generated php since contents fetched database

i.e.

<?php     ...     while($row = $sqlqry->fetch_object()) {         echo "<li class = 'lstoption' id = 'opt$row->name' data-value = '$row->total_count'>                   <h3>$row->given_reference<h3>               </li>";     }     ... ?> 

and sample structure based on javascript

<script>     $("ul li").click(function(){         alert($(this).data('value'));     }); </script> 

but if inject onclick= attribute while inside echo. script executed properly. need script work echo-ed html elements php.

try using variable interpolation syntax, i.e. wrap variables around curly braces

"{$var}" take note have use double quotes("") this

"<li class = 'lstoption' id = 'opt{$row->name}' data-value = '{$row->total_count}'>               <h3>{$row->given_reference}<h3>           </li>" 

Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -