php - Specifying jQuery for auto-assigned IDs? -


in foreach loop i'm creating divs (with paragraphs inside gotten mysql databases). i'd make them clickable (/connect them jquery).

problem 1: how create divs unique ids?

my solution: make counter , use attribute id="divclick<?php echo htmlspecialchars($count);?>"

problem 2: how write 1 jquery support divs?

my unfinished solution: $(document).ready(function(){ $("#divclick").focus(function(){ $("#buttonoption").animate({width:'toggle'}); });

so, how tweak jquery reacts divs 1 specific #buttonoption activated according div clicked.

simple. use shared class , data- attribute.

fiddle

<div data-button="<?php echo $count; ?>" id="divclick<?php echo htmlspecialchars($count); ?>" class="sharedclass"></div> 

then can bind click event in jquery this:

$(document).on('click', '.sharedclass', function() {     $("#buttonoption" + $(this).data('button')).animate({width:'toggle'}); }); 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -