Domanda

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 ;)

È stato utile?

Soluzione

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>
​
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top