How do i get the substring $v of the class rate$v? I can’t assign $v as an id and do attr('id') because i have $v assigned as an id to other elements. How do i get $v from the class rate$v in jquery?
<?php
foreach($v = 0; $v < 9; $v++) {
echo "<div class='raterow'><input type='hidden' class='rate$v' value='$username' /></div>";
}
?>
I’m assuming you want to get attributes of HTML printed with PHP, in jQuery. Correct me if I’m wrong.
Use a
data-attribute. It’s an HTML5 feature, but all (most) browsers will keep any attributes they don’t understand, so it’ll work in IE6, etc.Use
jQuery.data()to get that attribute and manipulate it. PHP:With this jQuery:
You can call
vIdwhatever you want, providing it’s prefixed withdata-. Note that.data()only needs the identifier part – you can excludedata-from the parameter you pass to it.