1

I'm a bit rusty on my HTML and JavaScript and can't seem to get this one right. The simple approach I took works fine, but I want to be more flexible. Here is the simple approach:

<head>

    <script>
        function loadContent(a){
            document.getElementById(a).innerHTML='<object type="text/html" data="home.html" ></object>';
        }
    </script>
</head>

<body>

    <div id="topBar"> 
        <a href ="#" onclick="loadContent('content')"> HOME </a> 
    </div>
    <div id ="content"> </div>

</body>

This works fine. However, I also want to get the desired document as a variable of the function. Here is where I get stuck. Probably has something to do with the "" and '', but I have not been able to find the answer. Here is my 'desired' situation:

<head>

    <script>
        function loadContent(a, b){
            document.getElementById(a).innerHTML= b;
        }
    </script>
</head>

<body>

    <div id="topBar"> 
        <a href ="#" onclick="loadContent('content', '<object type='text/html' data='home.html' ></object>')"> HOME </a> 
    </div>
    <div id ="content"> </div>

</body>

Can anybody help me out?

Thanx

1 Answer 1

3

Try:

<a href ="#" onclick="loadContent('content', '<object type=\'text/html\' data=\'home.html\' ></object>')"> HOME </a> 

Basically just escape the quotes.

Sign up to request clarification or add additional context in comments.

1 Comment

Cheers. Do accept the answer as solution if it worked..:)

Your Answer

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.