Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Comment ajouter du html dans du javascript:
- Je fais ce petit paste parce que cette question très simple semble complexe a trouver une réponse sur internet.
- Voici donc un exemple:
- $(function() {
- if ($('#WikiaRail').length) {
- $('#WikiaRail').bind('DOMNodeInserted.modules', function(event) { //fires after lazy-loading takes place.
- if ($('#WikiaRail section').size() && !$('#MyModule').size()) {
- $('#WikiaRail section:first-of-type').before("<section id='MyModule' class='module center'>"
- + CONTENT
- +"</section>");
- }
- }); //end of DOMNodeInserted block
- }
- });
- Nous souhaitons remplacer CONTENT par du html. Donc, comment insérer du html dans un javascript type celui-ci ?
- Simple, prendre la parcelle de code html et insérer de cette manière:
- $(function() {
- if ($('#WikiaRail').length) {
- $('#WikiaRail').bind('DOMNodeInserted.modules', function(event) { //fires after lazy-loading takes place.
- if ($('#WikiaRail section').size() && !$('#MyModule').size()) {
- $('#WikiaRail section:first-of-type').before("<section id='MyModule' class='module center'>"
- +'<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"> <input type="submit" value="Texte exact" class="searchboxSearchButton" name="fulltext"></form>'
- +"</section>");
- }
- }); //end of DOMNodeInserted block
- }
- });
- Donc pour insérer du html dans du javascript, les apostrophes.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement