2

I have the following html:

<div class="custom_title" contenteditable="true" maxlength="50">
   WRITE YOUR CUSTOM TITLE HERE
</div>

Then I do:

$("#search_wiki").on("click", function() {
  myGoogle();
});

Which calls:

var termS;  
function myGoogle() {
  termS = $(".custom_title").html();
  console.log(termS);

Yet when I change the text on that div, the console stills gives me the old text and not the new one

rob.m
  • 9,843
  • 19
  • 73
  • 162

2 Answers2

0

It works fine in the snippet:

$("#search_wiki").on("click", function() {
  myGoogle();
});

var termS;  
function myGoogle() {
  termS = $(".custom_title").html();
  console.log(termS);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="custom_title" contenteditable="true" maxlength="50">
   WRITE YOUR CUSTOM TITLE HERE
</div>

<h1 id="search_wiki">Search wiki</h1>
P.S.
  • 15,970
  • 14
  • 62
  • 86
  • yeah.. but not working on here, i'm going to try this https://stackoverflow.com/a/6256386/1018804 – rob.m Sep 21 '17 at 00:58
0

Just add jQuery on events inside ready event like this:

<script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  $(document).ready(function() {
    $("#search_wiki").on("click", function() {
      myGoogle();
    });
  });

and the html as you made:

<div class="custom_title" contenteditable="true" maxlength="50">
  WRITE YOUR CUSTOM TITLE HERE
</div>
<h1 id="search_wiki">Search wiki</h1>
Shiladitya
  • 12,003
  • 15
  • 25
  • 38
Mohamed Abulnasr
  • 589
  • 7
  • 18