0

Ive set up a fiddle here at JSFiddle!

My quetions is how do is use the the name of my input to traveserse up to the nearest TH, and get its content? In the fiddle case "www.sverigemotrasism.nu" should be fetched.

I have tried and tried many different solutions, getting a little closer each time.. But now im out of options, at least that's what I think!?

Take a look and if you know a how to solve it I would be really glad to hear how ;)

8bitcat
  • 2,206
  • 5
  • 30
  • 59
  • Can you provide the URL to your fiddle? This would help me see what you are trying to do. – ORION Sep 07 '12 at 18:39
  • 1
    There are some errors. First of all you placed the javascript in document.ready (jsfiddle does this automatically) which means the functions are out of scope from the onclick handlers. Then there's the fact that the `th` is'nt a parent of the `input`, so you'll need to first target the `tr` and then find the `th`. I got this far : http://jsfiddle.net/XqV2t/2/ – adeneo Sep 07 '12 at 18:53

1 Answers1

1

Since TH is not actually a parent of the INPUT but a higher-level sibling of the parent TD, I used .closest() to find the parent TR, then down to the target TH:

<script>
        var texten = $('#sverigemotrasism').closest('tr').find('th').text();
        alert(texten);
 </script>
​
Andy Merhaut
  • 305
  • 1
  • 6