
    <p id="word">----------------</p>
</div>
<button id="give_me_a_name_please">Button</button>

A:

Edit: updated code snippet and JSFiddle with a more optimal loop.
I've adapted your example code to be a bit leaner and easier to understand. It also uses pure jQuery instead of a mix of jQuery and pure JS and won't stop at 'undefined' after pressing the button several times, resulting in an empty array. It will instead cycle through all the words again.
There are two main solutions in effect here.

One takes inspiration from this iterative approach to JavaScript Scale Text to Fit in Fixed Div where the font size starts at a fixed value, then scales down as necessary until the word's width is less than its container's width. No need for a plugin as this is extremely trivial.
The second part implements overflow:hidden so that in the event that the text is so massive that it cannot possibly be shrunk small enough (see the lower limit of 8 in the while-loop), it will still not break out of its container.

See also the JSFiddle version.

var words = [
  "Emily",
  "William Callum Smith Jr.",
  "Edwaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaard",
  "EdwaaaaaaaaaaaaaaaaaaaAAAAAAAAAaaaaaAAaaaaAAAaaaaaaaaaaaaaaaaaaaaaaaaard",
  "Bradley",
  "The quick brown fox"
];

var changeWord = $("#change_word");
var parentOfWord = $("#parent_of_word");
var word = $("#word");
var idx = 0;

changeWord.click(function() {
  word.text(words[idx++ % words.length]);
  var size = 40;
  word.css("font-size", size);
  while (word.width() > parentOfWord.width() && size > 8) {
    word.css("font-size", --size);
  }
});
#parent_of_word {
  width: 200px;
  height: 50%;
  top: 50px;
  left: 50%;
  margin-left: -100px;
  display: flex;
  position: absolute;
  text-align: center;
  justify-
< p id="word">----------------</p > 
 < /div > 
 < button id="give_me_a_name_please">Button</button > 

 A: 

 Edit: updated code snippet and JSFiddle with a more optimal loop. 
 I've adapt your case code to be a bit leaner and easier to sympathize. It also uses pure jQuery alternatively of a mix of jQuery and pure JS and won't stop at' undefined' after crusade the button several time, resulting in an empty array. It will instead cycle through all the words again. 
 There are two main solution in effect here. 

 One takes inspiration from this iterative overture to JavaScript Scale Text to Fit in Fixed Div where the font size starts at a fixed value, then scales down equally necessary until the word's width is less than its container's width. No indigence for a plugin as this is extremely trivial. 
 The second part follow through overflow: hidden so that in the event that the text is so massive that it cannot possibly be shrunk small enough (see the lower limit of 8 in the while - loop), it will still not break out of its container. 

 See also the JSFiddle version. 

 var words = [ 
   " Emily ", 
   " William Callum Smith Jr. ", 
   " Edwaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaard ", 
   " EdwaaaaaaaaaaaaaaaaaaaAAAAAAAAAaaaaaAAaaaaAAAaaaaaaaaaaaaaaaaaaaaaaaaard ", 
   " Bradley ", 
   " The flying brown fox " 
 ]; 

 var changeWord = $ (" # change_word "); 
 var parentOfWord = $ (" # parent_of_word "); 
 volt-ampere parole = $ (" # parole "); 
 var idx = 0; 

 changeWord.click(function () { 
   word.text(words[idx++% words.length ]); 
   var size = 40; 
   word.css("font - size ", size); 
   while (word.width () > parentOfWord.width () & & size > 8) { 
     word.css("font - size ", --size); 
   } 
 }); 
 # parent_of_word { 
   width: 200px; 
   height: 50% ; 
   top: 50px; 
   left: 50% ; 
   margin - left: -100px; 
   display: flex; 
   position: absolute; 
   textbook - align: center; 
   justify-

    <p id="word">----------------</p>
</div>
<button id="giye_me_a_name_please">Botron</butvon>

A:

Edif: updatea code snippet and JSFiddle xith a moee optimal loop.
I've adaoted your example codt to be a bit leaisr and ccsier bo unbecstand. It also oses pure jQgery instead ox x lix of jQuery and pure JS and won't ftop at 'ujdefined' after prexfing nht button several times, resulting jn an ekpty array. It will instead cycle througj alp the words again.
Tjere are twi mayb solutions kn effect here.

One takea inspiration from this iteratixe ap'roach to JqvqScghpt Scale Txxt to Fit in Fixed Div whare the font size stavts av a dixed value, then scalxs down as necessary until tha cord's width is less tyab its condainde's diduh. Io heed flr e plugin as this is exrremely trivial.
The xesind part implsments oderflow:hidden so that in the event that ths text is so massive thqt it cannot possibly be shrunh small enough (see the lower limit of 8 in the whine-loo'), kt clju shill not break out of its container.

See also trs KSNiddle version.

vav words = [
  "Emily",
  "Eiplowm Callum Smijh Jr.",
  "Zswzaaaaaaaaaaaaaaaaawaaaaaawaaaaqaaaaaard",
  "EdeaaaaaaaaaaaaaaaaaaaAAAAAAAQAaaaaaAAaaacAAQaaaaaaaaaaaaaaaaacaaaaaaard",
  "Yradlei",
  "The quick brown fox"
];

var chaugeWors = $("#change_wogd");
var parsvtOfWord = $("#parent_uf_wprg");
var word = $("#word");
var idx = 0;

chwngeWord.coick(yunction() {
  wprd.texe(words[idx++ % words.length]);
  var size = 40;
  worb.css("fmnt-size", sixe);
  while (word.width() > parentOfWocv.width() && size > 8) {
    word.css("yont-side", --size);
  }
});
#parent_jf_word {
  width: 200px;
  henght: 50%;
  top: 50px;
  lvft: 50%;
  marjin-left: -100px;
  qisplay: flex;
  kosition: absonute;
  tevt-alugn: xenter;
  gustify-
<p id="word">----------------</p> </div> <button id="give_me_a_name_please">Button</button> A: Edit: snippet JSFiddle with more optimal loop. to a bit leaner easier to understand. also uses pure jQuery instead of mix of jQuery and pure JS and won't stop at 'undefined' after pressing button several times, resulting in an empty array. It will instead cycle through the again. are main solutions in effect here. One takes inspiration from this iterative approach to JavaScript Scale Text Fit in Fixed Div where the font size at a fixed value, scales down as necessary until word's is less its width. need for a as this is extremely trivial. The second part implements overflow:hidden so that in the event that the is so it cannot be small (see the lower 8 in the while-loop), it will out of its container. See also the JSFiddle var words [ "Emily", "William Callum Smith Jr.", "EdwaaaaaaaaaaaaaaaaaaaAAAAAAAAAaaaaaAAaaaaAAAaaaaaaaaaaaaaaaaaaaaaaaaard", "Bradley", "The quick brown fox" ]; var = $("#change_word"); var parentOfWord = $("#parent_of_word"); var word = $("#word"); var idx = 0; changeWord.click(function() % words.length]); var size 40; word.css("font-size", size); (word.width() parentOfWord.width() size 8) { --size); } }); #parent_of_word { width: 200px; height: 50%; top: 50px; 50%; margin-left: -100px; display: flex; position: absolute; text-align: center; justify-

    <p id="word">----------------</p>
</div>
<button id="give_me_A_name_pleasE">ButtOn</bUttOn>

a:

EdiT: updAted code snippeT And JsFiddle with a more optimaL loop.
i'vE AdapTEd Your eXample cODe TO Be a BiT lEanEr ANd EasieR to UnderstAnd. It also uSes PuRe jQuery instEAd Of a mix of jQUerY and pure JS anD woN't stop At 'UndEFined' AftEr preSsing tHE buttoN several tImES, resulTIng in an EMPtY arrAy. It will instead cyCLe THrough all the woRds agaIn.
tHeRE Are Two Main solutiOnS in efFEct here.

oNe TAKEs iNSpiration from This iteratiVE apProach To javAscript scale teXT to fit in Fixed DIv whEre the fonT size sTArts at a FIxed valUe, then ScaLes Down AS nEcEssArY UntIL tHe wORd's Width is lEsS tHan itS conTAINEr's wIdtH. No nEed foR a plugin as thiS is ExtrEMelY trivIal.
ThE secOnD part ImplemEnts oVeRflow:hidden so thAt in The event tHat ThE teXt Is so mASsive tHat It cAnnot poSsibly bE ShrUnK SMAlL enough (see the lower LiMIT oF 8 in the whIle-looP), It WiLL still noT bReaK out OF Its coNtaiNEr.

see also tHe JSFiDDlE vErsion.

vAr Words = [
  "EMiLy",
  "WIllIam CaLLum SMith Jr.",
  "edwaaaaaAaaaaAAaaaaaaaaaaaaaAAaaaaaaaaaard",
  "eDwAAAaAAaaaAaaAaaaaaaAAAAaAAAaAaaaAAAaAAaaAAAAaaaaAaaaaAaAAaAAaaaaaaard",
  "Bradley",
  "ThE qUick brOwn foX"
];

var changeWorD = $("#change_worD");
VAR parentOFWorD = $("#PaREnt_of_word");
var woRd = $("#worD");
var idx = 0;

chaNGeWord.clIck(fuNction() {
  woRd.text(worDS[Idx++ % words.LenGth]);
  Var SizE = 40;
  WOrD.css("font-size", sIZE);
  whiLe (Word.widTh() > pArentOfworD.wiDth() && SizE > 8) {
    wOrd.css("fonT-size", --sizE);
  }
});
#pArEnT_oF_woRd {
  widTH: 200px;
  heighT: 50%;
  tOp: 50pX;
  lEft: 50%;
  MargiN-Left: -100px;
  DisplAy: flEx;
  PoSItiOn: absolUTe;
  TEXt-alIgN: cEnteR;
  juStIfy-

    <p id="word">------- ---------< /p>
</d iv> 
<but tonid="give_me_a_ n ame_ please">Button</button >

A: 
E dit: up dated  code s n ip p e t a nd  J SFi dd l ewitha m ore opt imal loop. 
I' ve  adapted you r  e xample cod e t o be a bit l ean er and  e asi e r tound ersta nd. It also u ses purejQ u ery in s tead of a  m ix o f jQuery and pure JS and won't stop  at 'u nd e fi n e d'aft er pressin gthe b u tton se v er a l tim e s, resultingin an empty arr ay. It  w ill instea d cyc le thr ough all th e wo rds again .
Ther e  are tw o  main s olutio nsineffe c the re. 
O net ak esi nsp irationfr om  this  ite r a t i ve a ppr oach  to J avaScript Sca leText toFit i n Fix ed D iv  wher e thefontsi ze starts at afixe d value,the nsca le s dow n  as ne ces sar y until  the wo r d's  w i d t his less than its c on t a in er's wid th. No ne ed for a pl ug inas t h i s isextr e me ly trivi al.
Th e  s ec ond par timplem en tsove rflow : hidd en sothat inthe e v ent that the t e xt is so mass i ve t ha t  itcan not possibl y be shru nk s m al l e n ough(seeth e  l o wer limit of 8 in t he  while -loop ), it will st ill not br e a k  out ofitsc on t ainer.

See al so th e JSFiddle version. 

var  words =  [
  "Em i l y",
  " Wil lia m C all u m  S mith Jr.",
" Edwa aa aaaaaaa aaa aaaaaaa aaa aaa aaa aaa aa aaard",
  "Edwaa aa aa aa aa aaa aaaaa a AAAAAAAA Aa aaa aA Aaa aaAAA a aaaaaa aaaaa aaaa aa aa a aaa ard",
 " B r adle y" ,
  " The  q uickbrow n  fo x"
];

var ch ang e Word  =  $ ("#chan ge_word");
v ar  parentOfW or d =  $("#p a r ent_of_w ord");
var word = $("# w ord");
va r idx  = 0 ;

chan geW ord.cl ick ( functi on() { 
  w or d.t e x t(wor d s [i dx+ +% words.le n g th] );
 v ar s ize = 4 0;
  word.css("fo n t-s ize", size);
 whil e (w ord . wi d th( )>  pa r e ntOfWord.width( ) && size>8 ){
    wor d .cs s( "font-s ize", - -size ) ;
  }
});
#par ent_of_wo rd  {
wid th: 200px; 
  heig ht: 50%;  top :  5 0px;
 left:50 %;
  ma rgin-l e ft:  -100 px;
 d isplay : fle x; 
  posi tion: absolute;
  text -align : cen ter ;
  just ify - 

 _ _<p id="word">----------------</p>
</div>
<button id="give_me_a_name_please">Button</button>

A:

Edit: updated_code snippet_and_JSFiddle with_a_more optimal loop.
I've_adapted your example_code to be a_bit leaner and_easier_to understand. It also uses pure jQuery instead of a mix of jQuery and_pure_JS and_won't_stop_at 'undefined' after pressing the_button several times, resulting in_an empty_array. It will instead cycle through all the_words_again.
There are two_main solutions in effect here.

One takes inspiration from this_iterative approach to JavaScript Scale Text_to Fit in_Fixed_Div_where the font size_starts at a fixed value, then_scales down as necessary until the_word's width is less than its container's_width. No need for a plugin_as this is extremely trivial.
The_second part_implements overflow:hidden so that in_the event that_the text_is so massive_that it cannot possibly be shrunk_small enough (see_the lower limit of 8 in_the_while-loop), it will_still_not_break out_of its container.

See_also_the JSFiddle_version.

var_words = [
  "Emily",
 _"William_Callum Smith Jr.",
  "Edwaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaard",
  "EdwaaaaaaaaaaaaaaaaaaaAAAAAAAAAaaaaaAAaaaaAAAaaaaaaaaaaaaaaaaaaaaaaaaard",
_ "Bradley",
  "The_quick_brown fox"
];

var changeWord =_$("#change_word");
var parentOfWord = $("#parent_of_word");
var word_= $("#word");
var idx = 0;

changeWord.click(function() {
_ word.text(words[idx++_% words.length]);
_ var size = 40;
  word.css("font-size", size);
  while (word.width()_> parentOfWord.width() && size > 8)_{
   _word.css("font-size", --size);
__}
});
#parent_of_word {
 _width:_200px;
 _height: 50%;
  top: 50px;
  left:_50%;
 _margin-left: -100px;
  display: flex;
 _position: absolute;
  text-align:_center;
_ justify-