Dojo - Add an external style sheet outside the header

I would like to add an external stylesheet specified inside an Ajax call.

I found a way to do this using jQuery (see the example below), however I need to adapt this method to the dojo JavaScript framework.

JQuery example

$('head').append('<link rel="stylesheet" type="text/css" href="lightbox_stylesheet.css">'); 

Thanks.

+4
source share
3 answers

Once you have included dojo.NodeList-manipulate , it is almost identical to jQuery:

 dojo.require("dojo.NodeList-manipulate"); dojo.ready(function(){ dojo.query("head").append('<link rel="stylesheet" type="text/css" href="lightbox_stylesheet.css">'); }); 
+2
source

Try this using dojo.query

 dojo.query("head").forEach(function(node, index, array){ // append content af final of head node.innerHTML += '<link rel="stylesheet" type="text/css" href="lightbox_stylesheet.css">';}); 
+1
source

I figured it out

After a bit of a mess, I came up with the following:

 function require_css(href) { if (typeof href == 'undefined' || href.length == 0) return false; var link = dojo.create("link", { type : "text/css", rel : "stylesheet", href : href }); dojo.doc.getElementsByTagName("head")[0].appendChild(link); console.log("loading : css : "+ href); } 

Thanks for the input guy .. I prefer the thirtydot method of mine: D ..

+1
source

All Articles