0

I am using this code to include a file (thanks M1K1O):

jQuery Code:

    <script language="javascript">
$(function(){
  $(".classloader").click(function(){
    $("#contenthere").load("/includes/about-info.html");
  });
});
</script>

HTML Code:

<p class="classloader">Click Here</p>
<div id="contenthere"></div>

But I have problems with character encoding. The included file is saved as iso-8859-2, the main html file is too but still I get "bushes".

How can I solve the problem?

And second question: after a click on 'Click here' text from a file is included. I would like the second click to erase the loaded content. Is that possible?

Thank you in advance for your help :)

Karolina

1
  • I solved first problem, I think. Looks like included file should be coded as UTF-8 although main file (where I make an inclusion) is coded as iso-8859-2. Strange. Second question is still active. Does anyone know the solution? :-) Commented Oct 28, 2017 at 4:33

2 Answers 2

1

You can adapt your event listener to "toggle" on clicking by checking to see if the #contenthere div is populated with your html:

<script language="javascript">
 $(function(){
  $(".classloader").click(function(){
    if($('#contenthere').html() == ""){
      $("#contenthere").load("/includes/about-info.html");
    } else {
      $('#contenthere').html("");
    }
  });
});
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

Works great. Thank you!
0

simply $('#elementId').html(""); is used for clear the elements of the selector

Then,

For empty/clear the input use $('#elementId').val("");

1 Comment

Thanks! This is it.

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.