0

I m trying to get a alert if clicked on th button where the first value in the list is displayed. I m using the following code based on this threat. In this threat they are using a table not a list. But i thought that that was not a problem... i think it is now. The code i m using is this.( The features are from a openlayer map):

<ul id ="table_overvieuw">
<#list features as feature>
  <li><b>Type: ${type.name}</b> (id: <em>${feature.fid}</em>):
  <ul>
  <#list feature.attributes as attribute>
    <#if !attribute.isGeometry>
      <li><b>${attribute.name}</b></li>
      ${attribute.value}
    </#if>
  </#list>
  <br><br>
 <input type="button" name="geef slijpplaten info" class="ok" value="OK" onclick="myFunction()" />
  </ul>
  </li>
</#list>
</ul>
<script type="text/javascript">
function highlight(e) {
    if (selected[0]) selected[0].className = '';
    e.target.parentNode.className = 'selected';
}

var table = document.getElementById('table_overvieuw'),
    selected = table.getElementsByClassName('selected');
table.onclick = highlight;

function myFunction(){

    alert($("li.selected li:first" ).html());
}

</script>

The error i m getting in the console is : Uncaught ReferenceError: $ is not defined. The $ is from this piece of code:

 alert($("li.selected li:first" ).html());

can somebody give me a helping hand?

Community
  • 1
  • 1
waywer
  • 21
  • 11

2 Answers2

1

To use jquery you must to have it on you page. Use CDN (http://jquery.com/download/#using-jquery-with-a-cdn). Also you can install it with bower (bower install jquery) and link it on page:

<html>
<head>
    <script src="/bower_components/jquery/dist/jquery.min.js"></script>
...
</head>
...
</html>
0

If the list box is being properly formed then try the code below inside the alert box:-

$('ul#table_overview li:first').text()
Webdev
  • 617
  • 6
  • 24
  • where do i need to place this exactly? – waywer Mar 08 '16 at 13:01
  • function myFunction(){ alert($("li.selected li:first" ).html()); } Replace the existing code with the code above – Webdev Mar 08 '16 at 13:03
  • can you explain to me what it does? because i filled it in(with a alert for the $) and the alert has a responce with nothing in it – waywer Mar 08 '16 at 13:07