So i have this function in my Js that gets called on a link onclick() event.
here is the HTML:
<li class="collapsed">
<span>
<a href="#!" onclick="expand(this)">Directions</a>
</span>
<p>ajajgajajys agajgjgtajgtdja ajdtajtjate ajgdjagjd ajt</p>
</li>
And here is the Javascript:
function expand(myElem)
{
if (myElem.parentNode.parentNode.style.height<100)
myElem.parentNode.parentNode.style.height="100px";
else
myElem.parentNode.parentNode.style.height="45px";
}
Obviosuly, the code expands the li parent tags that the links are in. Originally, the li tags are set as height:45px;
in CSS. Then they change to 100px
and back.
The problem im having is that the javascript only works twice.
I cna click on the links oncde and expand the li's. Then i can click on them and collapse the li's. Then it doesn't want to work again.
I was looking at my browsers errors and i found this:
"Error parsing value for 'height'. Declaration dropped.
After much trolling thru the interwebs I thought it might be because i'm not including the unit declarations in my js. But I am!
myElem.parentNode.parentNode.style.height="45px"; ---- as you can see.
****NOTES: MY SOLUTION*****
For future referance for whoever stumbles on this thread, here's my solution:
HTML --> I ened up doing somethin glike:
<span class="heading">
Link1
<span>
<span class="information">
Info about Link1
</span>
<span class="heading">
Link2
<span>
<span class="information">
Info about Link2
</span>
And the Jquery was super simple:
$(document).ready(function() {
$(".information").hide();
$(".heading").click(function(){
var item = $(this);
item.next().slideToggle(500);
});
});
...super simple, works like a charm