johnsonallstars
asked on
Auto increment in jQuery script
Hello,
I have working script for a jQuery dialog message.
Here's the code:
<script>
$(function() {
var dialog
dialog = $( '#dialog-message1' ).dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
Cancel: function() {
dialog.dialog( 'close' );
}
},
close: function() {
}
});
$( '#create-explanation1' ).button().on( 'click', function() {
dialog.dialog( 'open' );
});
});
</script>
on the page results I have:
//the 1st message works with jQuery dialog
<div id='dialog-message1' title='Explanation'>Some information for the 1st message</div><button id='create-explanation1'>E xplanation </button>
//as you can see the 2nd, 3rd, 4th messages will not work as I have the script above.
<div id='dialog-message2' title='Explanation'>Some information for the 2nd message</div><button id='create-explanation2'>E xplanation </button>
How can I update or I perhaps auto increment the number in the script? So, that each time I call the button the script will work for that message 1,2,3,4,5 etc.
Thanks in Advance.
I have working script for a jQuery dialog message.
Here's the code:
<script>
$(function() {
var dialog
dialog = $( '#dialog-message1' ).dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
Cancel: function() {
dialog.dialog( 'close' );
}
},
close: function() {
}
});
$( '#create-explanation1' ).button().on( 'click', function() {
dialog.dialog( 'open' );
});
});
</script>
on the page results I have:
//the 1st message works with jQuery dialog
<div id='dialog-message1' title='Explanation'>Some information for the 1st message</div><button id='create-explanation1'>E
//as you can see the 2nd, 3rd, 4th messages will not work as I have the script above.
<div id='dialog-message2' title='Explanation'>Some information for the 2nd message</div><button id='create-explanation2'>E
How can I update or I perhaps auto increment the number in the script? So, that each time I call the button the script will work for that message 1,2,3,4,5 etc.
Thanks in Advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I am also looking for this. But I have a one question:
1) I want to generate 'id' and 'data-target' incrementally and dynamically with jquery
so that I just need one line of code for <button> tag
How can I do this?
1) I want to generate 'id' and 'data-target' incrementally and dynamically with jquery
so that I just need one line of code for <button> tag
How can I do this?
Something like.
Open in new window
I didn't test out the code so sorry if there are any typos (I am on an iPad), but hopefully the idea comes across and helps.