Advertisement
Io-EE

insérer du html dans du javascript

Mar 27th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Comment ajouter du html dans du javascript:
  2. Je fais ce petit paste parce que cette question très simple semble complexe a trouver une réponse sur internet.
  3. Voici donc un exemple:
  4. $(function() {
  5.   if ($('#WikiaRail').length) {
  6.     $('#WikiaRail').bind('DOMNodeInserted.modules', function(event) { //fires after lazy-loading takes place.
  7.       if ($('#WikiaRail section').size() && !$('#MyModule').size()) {
  8.         $('#WikiaRail section:first-of-type').before("<section id='MyModule' class='module center'>"
  9.           + CONTENT
  10.           +"</section>");
  11.       }
  12.     });  //end of DOMNodeInserted block
  13.   }
  14. });
  15.  
  16. Nous souhaitons remplacer CONTENT par du html. Donc, comment insérer du html dans un javascript type celui-ci ?
  17. Simple, prendre la parcelle de code html et insérer de cette manière:
  18. $(function() {
  19.   if ($('#WikiaRail').length) {
  20.     $('#WikiaRail').bind('DOMNodeInserted.modules', function(event) { //fires after lazy-loading takes place.
  21.       if ($('#WikiaRail section').size() && !$('#MyModule').size()) {
  22.         $('#WikiaRail section:first-of-type').before("<section id='MyModule' class='module center'>"
  23.           +'<form action="/wiki/Special:Search" class="searchbox" id="searchbox" name="searchbox"><input type="text" size="30" placeholder="Intervalle, page..." value="" name="search" class="searchboxInput"> <input type="submit" value="Rechercher" class="searchboxGoButton" name="go">&nbsp;<input type="submit" value="Texte exact" class="searchboxSearchButton" name="fulltext"></form>'
  24.           +"</section>");
  25.       }
  26.     });  //end of DOMNodeInserted block
  27.   }
  28. });
  29.  
  30. Donc pour insérer du html dans du javascript, les apostrophes.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement