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

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -