sikas
sikas

Reputation: 5523

getting ID of <li> in javascript function

I'm trying to get the ID of a <li> item.

The item is as follows:

echo ($y<$sites-1)?"<li id='" . $sit[0] ."'>":"<li id='$sit[0]' class=\"last\">";
echo "<a href=\"javascript:selectedSite();\" onClick=\"javascript:submit(1);\" onMouseOver=\"mouseAction(1)\" onMouseOut=\"mouseAction(0)\">" . $sit[1] . "</a></li>";

and this is my function:

function selectedSite()
{
    alert(/*I want the ID goes here*/);
}

Upvotes: 0

Views: 104

Answers (1)

user142162
user142162

Reputation:

If you have to do it inline, the following will work for you:

echo "<a href=\"#\" onClick=\"selectedSite(this);submit(1);\" ...
function selectedSite(item)
{
    alert(item.parentNode.id);
}

Upvotes: 6

Related Questions