Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7524621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:07:12+00:00 2026-05-30T03:07:12+00:00

Hi I asked before on how to load a div’s content (A url) by

  • 0

Hi I asked before on how to load a div’s content (A url) by clicking a button and not on page load before and I got this code as an answer:

<script type="text/javascript">
    function toggleDiv(id){
        if ($('#' + id).html() == '') {
            $.ajax({
                url: 'api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=SOMETHING&from=en&to=de&text=Hello', // your url to microsoft translator
                success: function(data) {
                    $('#' + id).html(data);
                },
                error: function() {
                    $('#' + id).html('The resource could not be loaded');
                }
            });
        }

        $('#' + id).toggle(); // Toggle div visibility
    }
</script>

<a href="#" onclick="toggleDiv('a')">Show/Hide Value</a>
<div id="a" style="display:none"></div>

First of all it doesn’t work correctly and always show “The resource could not be loaded” if you put a txt link like (http://knowpersia.com/a.txt) it doesn’t work either.
Secondly the Show/Hide Value link uses a href=# and onclick system to work. When I use it on my website it gets back to the homepage when I click it. Is there a way to change it to something like:

<a href="javascript:toggleDiv('a')">Show/Hide Value</a>

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T03:07:13+00:00Added an answer on May 30, 2026 at 3:07 am

    You have to pass an id to the toggleDiv() function, and you’re passing a collection of objects -> toggleDiv('a') // Nop.
    Also, if you’re using jQuery, I suggest you get rid of that ugly inline code. Then, you can pass jQuery objects into your function:

    <a href="#" id="link">Show/Hide Value</a>
    <div id="content"></div>
    

    .

    var toggleDiv = function($el) {
        if ($el.empty()) { // You can just use `empty()`
            $.ajax({
                url : 'api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=SOMETHING&from=en&to=de&text=Hello', // your url to microsoft translator
                success : function (data) {
                    $el.html(data);
                },
                error : function () {
                    $el.html('The resource could not be loaded');
                }
            });
        }
        $el.toggle(); // Toggle div visibility
    };
    
    $('#link').click(function(){ toggleDiv($('#content')); });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had asked this question before, but I got no correct answer. So, this
I know this has been asked many times before... I have a simple ('#Div').load(file.php?id='+id+'&page='+page)
I've asked this question before but I didn't seem to get the right answer.
i'm reposting this question because i'm not sure if i asked it correctly before.:)
I know this has been asked before but I have looked at every answer
I know this has been asked before, but i can't find a good answer
I know this question has been asked before but the solutions did not work
This question was asked before here , but can't say that the answer helps
This question may have been asked before, but I couldn't find an answer to
I have asked this question before and it seemed that the code I was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.