1

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
2
  • 1
    Can you post the complete code you're using? Commented Oct 3, 2013 at 21:03
  • when you call it add this to 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 Commented Oct 3, 2013 at 21:04

3 Answers 3

8

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
Sign up to request clarification or add additional context in comments.

Comments

4

Try putting quotes around 300px, i.e.

<script>
function expand()
{
 parent.getElementById("elementA").style.height = '300px';
}
</script>
answered Oct 3, 2013 at 21:03

Comments

0

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.

answered Oct 3, 2013 at 21:08

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.