guys I'm not very familiar with Javascript and the usage of regular expressions I've spent hours digging through resources and trying multiple different ways and just can't seem to get it to work.
I have a menu where when you click the links a modal window will pop up. Currently I have 18 of these links on a page - so there is 18 different modal windows. I have each labeled in the php file like so:
<div class="button_menu">
<a href="#dialog0" name="modal0" /><div class="button">HQ</div></a>
</div>
Then at the bottom of the PHP File I have this.
<div id="dialog0">
(Omitted)
</div>
<div id="mask"></div>
This will repeat 18 times from dialog0 - 17 and modal0 - 17.
The JS code is the simple jQuery Modal code that I got off a tutorial at: http://www.queness.com/post/77/simple-jquery-modal-window-tutorial
The code in question where I just can't regular expressions to work is here:
$('a[name=modal'.match(/[0-9]/)']').click(function(e) {
//Cancel the link behavior
e.preventDefault();
//Get the A tag
var id = $(this).attr('href');
And here.....
//if close button is clicked
$('.X, #dialog'.match(/[0-9]/)).click(function (e) {
//Cancel the link behavior
e.preventDefault();
$('#mask, #dialog'.match(/[0-9]/)).hide();
});
What am I doing wrong? Thank you in advance for the help.
You can use a data attribute on your modals to pass data to your modal open function or a class , or partially match the name: below is an example of using a class to trigger the event and you simply need to retrive the id of the dialog to open.
Fiddle here
HTML
jQuery