I'm working on a project based on schools and one of the features we have is school finder.
Because schools like to continue using Windows XP and stuck with Internet Explorer 1 (pun intended), I'm trying to use tradition javascript, rather than jQuery to support all browsers.
The problem is, the schools listed from the database are put into tables, each having a custom attribute called data-school-id with a value of sch-X
I am truly stuck on how to get javascript to read these values when the user clicks on the school's table cell. This is the code I currently have:
var schID = document.getElementById("data-school-id");
schID.addEventListener("click", function() {
alert(schID.value);
}, false);
I need to grab the numeric value, though I already know how to do that. It's getting javascript to understand the dynamic attributes and it's value for each table cell that I'm stuck on.
Each of the table cells are as so:
<td data-school-id="sch-123">
<div class="pull-left sch-logo">
<img src="#" width="100" height="100">
</div>
<div class="pull-left">
<h3>School Name</h3>
<p><strong>Headteacher:</strong> Mr. Foo Bar</p>
</div>
</td>