Is it possible to guarantee a unique id for multiple items using the same id variable at a point in
Posted
by Scarface
on Stack Overflow
See other posts from Stack Overflow
or by Scarface
Published on 2010-04-11T05:33:58Z
Indexed on
2010/04/11
5:43 UTC
Read the original article
Hit count: 247
First of all, do not be overwhelmed by the long code, I just put it for reference...I have a function that preg_replaces content and puts it in a jquery dialog box with a matching open-link. For example, if there is a paragraph with two matches, they will be put inside two divs, and a jquery dialog function will be echoed twice; one for each div.
While this works for one match, if there are multiple matches, it does not. I am not sure how to distribute unique ids at a point in time for each of the divs and matching dialog open-scripts. Keep in mind, I removed the preg replace function since it kind of complicates the problem. If anyone has any ideas, they will be greatly appreciated.
<?php
$id=uniqid();
$id2=uniqid();
echo "<div id=\"$id2\">
</div>";
?>
$.ui.dialog.defaults.bgiframe = true;
$(function() {
$("<?php echo"#$id2"; ?>").dialog({hide: 'clip', modal: true
,width: 600,height: 350,position: 'center',
show: 'clip',stack: true,title: 'title', minHeight: 25,
minWidth: 100, autoOpen: false});
$('<?php echo"#$id"; ?>').click(function() {
$('<?php echo"#$id2"; ?>').dialog('open');
})
.hover(
function(){
$(this).addClass("ui-state-hover");
},
function(){
$(this).removeClass("ui-state-hover");
}
).mousedown(function(){
$(this).addClass("ui-state-active");
})
.mouseup(function(){
$(this).removeClass("ui-state-active");
});
});
© Stack Overflow or respective owner