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
  • 8,849
  • 15
  • 70
  • 137

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>
Commercial Suicide
  • 14,875
  • 14
  • 62
  • 80
  • 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
  • 11,650
  • 15
  • 23
  • 35
Mohamed Abulnasr
  • 559
  • 7
  • 18