php - How Can I do for manipulate html tags inside of a template in jquery tmpl? -
i have problem, can't access outside of jquery template manipulate html code. result: []
i have template:
<script id="tmpl" type="text/x-jquery-tmpl"> <select id="country"> <?php $query = 'select country_id, country_name countries'; $results = $wpdb->get_results($query, object); foreach($results $result) { echo '<option value="'.$result->country_id.'">'.$result->country_name.'</option>'; } ?> </select> <span value="${countryhelpers(user.country)}" /> </script>
and outside of template have code javascript
<script type="text/javascript"> function countryhelpers(country) { $("#country option[value='"+country+"']").attr("selected",function(){return "selected";}); }
how put attr "selected"
thanks!
you can try this:
function countryhelpers(country) { $("#country option").filter(function() { return $(this).text() === country }).attr('selected', true); }
edit: there similar question: selecting option in dropdown menu based on node value?
Comments
Post a Comment