0

I am having one issue with document.ready jQuery function.

On load the document.ready function is working fine. When I click on the button or href link, I want to reconnect with the document.ready function where I have set of code in JavaScript file.

Here is the actual scenario. Please find below sample JS code:

$(document).ready(function() {
      var title = "This is your title";    
      var shortText = jQuery.trim(title).substring(0, 10).split(" ").slice(0, -1).join(" ") + "...";    
alert(shortText );
});

After clicking submit button i am adding the input fields data in the below table row. In which description texts are also added in one of table row columns. If description field has more than 100 character, I am pushing the above mentioned JavaScript code from external .JS file. How can i refresh the Java script function without refreshing the page? Anyone have idea?

Please share your opinion.

Vasethvan
  • 391
  • 1
  • 4
  • 12

1 Answers1

0

Create a function, that you can call both in document.ready, and also anywhere else, such as a buttons click event:

function myfunc(){
    var title = "This is your title";    
    var shortText = jQuery.trim(title).substring(0, 10).split(" ").slice(0, -1).join(" ") + "...";    
    alert(shortText );
}

$(document).ready(function() {
      //call  when document is ready
      myfunc();
      //call again when button is clicked
      $('#button').click(myfunc());
});
Steve
  • 20,703
  • 5
  • 41
  • 67