I have a block of HTML markup that looks something like this for a Course. This is predefined by the CMS my client's using
<ul class="box-3036">
<li aria-selected="true">
<a href="#" id="ui-id-5">Dentistry</a>
</li>
</ul>
I have a bunch of courses, here's another example of this HTML block for another course.
<ul class="box-3032">
<li aria-selected="true">
<a href="#" id="ui-id-7">Pharmacy</a>
</li>
</ul>
I am trying to write a jQuery code for all these courses. From the HTML block, here are the unique info
- the
<ul>class - the
<a>id - and the
<a>click will open up two course URLs
Here's the jQuery code I have now. The problem I am facing is that the URL vars is giving me undefined value
box = [
".box-3036",
".box-3032"
];
uiid = [
"a#ui-id-5",
"a#ui-id-7"
];
urlfirst = [
"http://www.yahoo.com",
"http://www.gmail.com"
];
urlsecond = [
"http://www.google.com",
"http://www.7senarai.com "
];
for (var i = 0; i < box.length; i++) {
$(box[i] + " " + uiid[i]).click(function() {
var pid = $(this).parent().attr("aria-selected");
if(pid == "true") {
//window.open(urlfirst[i], '_blank');
//window.location.href = urlsecond[i];
alert(urlfirst[i]);
alert(urlsecond[i]);
}
});
}
Here's my jsfiddle