I've defined a javascript function:
<script>
function expand()
{
parent.getElementById("elementA").style.height = 300px;
}
</script>
I'm trying to call it onClick:
<div id="elementB" onclick="expand()">Notif</div>
The web console tells me that expand is not defined when I click on it.
asked Oct 3, 2013 at 21:02
Juicy
12.6k40 gold badges135 silver badges221 bronze badges
3 Answers 3
You have a syntax error in your javascript, it should be '300px' (a string); This is why the script does not load (which web console probably also tells you), so the function is not defined.
answered Oct 3, 2013 at 21:03
Alexander Gessler
46.9k7 gold badges87 silver badges124 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Try putting quotes around 300px, i.e.
<script>
function expand()
{
parent.getElementById("elementA").style.height = '300px';
}
</script>
answered Oct 3, 2013 at 21:03
mdml
23k8 gold badges61 silver badges66 bronze badges
Comments
When assigning the value for height, you must assign it as a string value.
<script type="text/javascript">
function expand()
{
// Need to assign the value as a string
parent.getElementById("elementA").style.height = '300px';
}
</script>
I'm assuming this is within an iframe given the parent reference. If not, you might want to change parent to document.
Comments
lang-js
thisto your function call in the dom.expand(this). this will pass a reference to the dom element that the event is attached to. just an fyi