0

please look this code : CODE

this code work in jsfiddle.net but not work on local js code in local , this code show and hide more less text

<script type="text/javascript" src="jquery-1.8.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
      var maxheight=118;
      var showText = "More";
      var hideText = "Less";

      $('.textContainer_Truncate').each(function () {
        var text = $(this);
        if (text.height() > maxheight){
            text.css({ 'overflow': 'hidden','height': maxheight + 'px' });

            var link = $('<a href="#">' + showText + '</a>');
            var linkDiv = $('<div></div>');
            linkDiv.append(link);
            $(this).after(linkDiv);

            link.click(function (event) {
              event.preventDefault();
              if (text.height() > maxheight) {
                  $(this).html(showText);
                  text.css('height', maxheight + 'px');
              } else {
                  $(this).html(hideText);
                  text.css('height', 'auto');
              }
            });
        }       
      });
   });​
</script>

htm code :

<div class="textContainer_Truncate">
      <p>content<br>
        hello<br>
        hello<br>
        hello<br>
          hello<br>
          hello<br>
          hello<br>
          hello<br>
          hello<br>
          hello<br>
          hello<br>
          hello<br>
          hello<br>
          hello<br>
          hello<br>
          hello<br>
          hello<br>
        </p>
    </div>

content of folder : index.htm and jquery-1.8.2.min.js how to use this code on local ?

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
Mohammad
  • 197
  • 3
  • 12
  • 1
    Please define 'not work' (as this can mean a lot of things - from slight hiccups in JS behaviour to blowing up the whole computer; hopefully, it's not the latter) and show the complete source of that HTML file (index.htm that is). – raina77ow Oct 22 '12 at 13:54
  • is "jquery-1.8.2.min.js" the correct include path? – dokaspar Oct 22 '12 at 13:59
  • Check this fiddle http://jsfiddle.net/zbjhX/ . It is created by me based on your script and html. Its working fine. Plz check your script references in your local code. – Dhanasekar Murugesan Oct 22 '12 at 14:00

1 Answers1

3

I've tried to replicate what you have done and found that it's working fine with no error.

consider to download this solution (a folder contains an index.html page along side with jquery 1.8.2.js file). maybe you have made something extra Test Project

Update: I've noticed something when copying your code, there is an extra questionmark in your code, look at the following picture

enter image description here

Mohammed Swillam
  • 9,119
  • 4
  • 36
  • 47