Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
86
rated 0 times [  87] [ 1]  / answers: 1 / hits: 51275  / 13 Years ago, tue, june 21, 2011, 12:00:00

When I click on the show details link it should change to hide details. I tried the following code but it's not working:



out.print(<a href=javascript:parent.showHideDetails('+id+',this);>show details</a>);

function showHideDetails(id,obj) {
try
{

alert(obj.innerText);
obj.innerText = 'hide details';
}
catch (err)
{
alert(err);
}

}

More From » javascript

 Answers
22

The problem is that this in your href attribute doesn't point to the anchor. You could pass an identifier there, and give the anchor element the same identified as id attribute; and then use document.getElementById to get the anchor.



Example:



out.print(<a href=javascript:parent.showHideDetails('+id+','anchor_1'); id=anchor_1>show details</a>);

function showHideDetails(id,identifier) {
try
{
var obj = document.getElementById(identifier);
alert(obj.innerText);
obj.innerText = 'hide details';
}
catch (err)
{
alert(err);
}
}

[#91591] Monday, June 20, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
harleew

Total Points: 70
Total Questions: 87
Total Answers: 117

Location: Namibia
Member since Mon, Feb 21, 2022
2 Years ago
;