08 March 2016

Add or remove a CSS stylesheet to HTML using plain vanilla Javascript

This little function will attach or delete a new stylesheet to your html page using good old JS. The second parameter is optional so it will toggle on or off the stylesheet, depending on it's current setting. The function will return true or false (1 or 0), depending on weather the style is on or off. Enjoy!


function toggleStylesheet(href,onoff){
    var existingNode=0 //get existing node:
    for(var i = 0; i < document.styleSheets.length; i++){
        if( document.styleSheets[i].href && document.styleSheets[i].href.indexOf(href)>-1 ) existingNode = document.styleSheets[i].ownerNode
    }
    if(onoff == undefined) onoff = !existingNode //toggle on or off if undefined
    if(onoff){ //TURN ON:
        if(existingNode) return onoff
        var link  = document.createElement('link');
        link.rel  = 'stylesheet';
        link.type = 'text/css';
        link.href = href;
        document.getElementsByTagName('head')[0].appendChild(link);
    }else{ //TURN OFF:
        if(existingNode) existingNode.parentNode.removeChild(existingNode)
    }
    return onoff
}

//EXAMPLES:

toggleStylesheet('myStyle.css') //toggle myStyle.css on or off

toggleStylesheet('myStyle.css',1) //add myStyle.css

toggleStylesheet('myStyle.css',0) //remove myStyle.css

25 comments:

Meiqing Xu said...

coach factory outlet
nike free run flyknit
coach outlet
ugg outlet store
oakley sunglasses
adidas super color
pandora charms
nike shoes for men
converse shoes
christian louboutin
20161228caiyan

Gembiraria said...

hajar wess omz AGUNGQQ Agen DominoQQ, BandarQ, Capsa Susun, QQ Online Terpercaya di Indonesia

Agen Bandar66 Online Judi Sakong Capsa BandarQ Domino99 Keris99

ituCasino Agen Bola Sbobet Piala Dunia 2018 Live Casino Online

Judi Sbobet LiveCasino 338a Agen Bola Piala Dunia Online KiosCasino

daftar poker online said...

Mrjudibola.com agen bola terpercaya

Mrjudibola.com Bandar bola terpercaya

Daftar Poker Online

Poker Online Indonesia

Situs Berita terkini

Detik Siang

agen domino qq terpercaya said...

BwinQQ.casino agen dominoqq terpercaya

BwinQQ.casino situs dominoqq terpercaya

BwinQQ.casino situs poker online terpercaya

BwinQQ.casino agen poker terpercaya

bandarqiu99.info situs domino99 terpercaya

AGUNGQQ Agen DominoQQ, BandarQ, Capsa Susun, QQ Online Terpercaya di Indonesia said...

AGUNGQQ Agen DominoQQ, BandarQ, Capsa Susun, QQ Online Terpercaya di Indonesia

Agen Bandar66 Online Judi Sakong Capsa BandarQ Domino99 Keris99

ituCasino Agen Bola Sbobet Piala Dunia 2018 Live Casino Online

Judi Sbobet LiveCasino 338a Agen Bola Piala Dunia Online KiosCasino

obat aborsi ampuh said...

cara menggugurkan kandungan

cara ampuh menggugurkan kandungan

obat aborsi

obat aborsi ampuh

cara menggugurkan kandungan said...

allways good ide for write high quality content in this blog
Cara Menggugurkan kandungan

Obat Aborsi

obat aborsi

cara menggugurkan kandungan

obat aborsi

cara menggugurkan kandungan

cara ampuh menggugurkan kandungan

cara menggugurkan kandungan

obat aborsi

obat penggugur kandungan

chenlili said...

coach outlet
michael kors outlet
nfl jerseys wholesale
christian louboutin outlet
coach outlet online
canada goose outlet
canada goose outlet store
canada goose outlet
christian louboutin sale
pandora outlet
shenyuhang20180608

Julie T. Kirwan said...

https://titaniumbackup.pro/apk/
https://esfileexplorer.pro/apk/
https://beachbuggyracingmod.xyz/apk/

Amy Wong said...

what about your finances not bad but everything is just gorgeous Do you want to share with you how to make money sitting on the Internet come here crackajack video poker machines I wish you good luck earning head

Belago said...

Качественная лед лента разных цветов, герметичные и нет, я обычно беру в Экодио

على جمال said...

شركة مكافحة الحشرات بالرياض
شركة مكافحة النمل الابيض بالرياض
شركة مكافحة النمل الاسود بالرياض
شركة مكافحة الفئران بالرياض
شركة مكافحة الصراصير بالرياض
شركة مكافحة البق بالرياض
شركة مكافحة الوزغ بالرياض
شركة مكافحة الثعابين بالرياض
شركة رش دفان بالرياض
شركة رش مبيدات بالرياض

Unknown said...

This is a wonderful article, obat aborsi cytotec asli Given so much info in it, These type of articles keeps the users obat aborsi surabaya interest in the website, and keep on sharing more ... good luck cara menggugurkan kehamilan.

yanmaneee said...

nike react
yeezy boost 350
off white nike
christian louboutin shoes
hermes birkin
hermes handbags
kd 11
lebron shoes
yeezy
michael kors handbags

Sidaring said...

Can I just say what a relief to find someone who actually knows what theyre talking about on the internet. You definitely know how to bring an issue to light and make it important. More people need to read this and understand this side of the story. I cant believe youre not more popular because you definitely have the gift.
Aplikasi Dapodikdasmen Terbaru
Sidaring

محمد على said...

شركة تسليك مجارى بالرياض
شركة تنظيف كنب بالرياض
شركة تنظيف خزانات بالرياض
شركة عزل خزانات بالرياض

kayan web said...

House cleaning company in Hail represents the best and ideal solution for specialized and distinctive cleaning of all pieces of furniture and house rooms no matter the number of floors of the house and the number of rooms, where we work through a team trained on modern methods of cleaning using the latest steam cleaning machines that give outstanding results in cleaning sofas, boards, carpets and rugs It is also used to clean curtains and furnishings.Ceramic floors, chimneys and hoods are cleaned from hard fat stains and rust stains safely and completely.We also provide marble polishing services by providing the latest Italian marble polishing machines with the best types of detergents Its excellent cleaning and disinfecting houses cleaning company examples in Hail is the best choice and cheaper.
شركة تنظيف بحائل
شركة تنظيف فرش بحائل
شركة تنظيف مجالس بحائل
شركة تنظيف سجاد بحائل
شركة تنظيف منازل بحائل
شركة رش مبيدات بحائل
https://www.raya-hail.com

kayan web said...

Al-Najah Company is one of the most distinctive things about Al-Ahsa cleaner company. Cleanliness of furniture, and some individuals are responsible for the operation of devices, whether pumping devices or suction, and there is a team responsible for the process of sterilization air conditioners , Our team is considered one of the best teams because of its vast experience over many years in this field, skill and high efficiency, and fast and perfect performance. The nature of the work of the team and what may be seen when carrying out its mission, and we have a team of women to be at the service of our valued customers so as not to worry about the entry of the team of men to come home in the presence of women and housewives.
شركة تنظيف بالاحساء
شركة تنظيف مكيفات بالاحساء
شركة تسليك مجارى بالاحساء
شركة مكافحة حشرات بالاحساء
https://www.a-lnagah.com

kayan web said...

شركة تنظيف بالمدينة المنورة
شركة نظافة بالمدينة المنورة
https://www.cleaningcompanyusa.com/

kayan web said...

شركة الصفرات للتنظيف بالرياض
شركة الصفرات لتنظيف الخزانات بالرياض
شركة الصفرات لمكافحة الحشرات بالرياض
شركة الصفرات لنقل الاثاث بالرياض
شركة الصفرات لكشف التسربات بالرياض
https://www.beat-elkhibra.com/

kayan web said...

Welcome to the official website of our company to clean apartments, houses, villas and shops in Saudi Arabia This is because we are the best home services company at the moment and by the testimony of our valued customers, the workers who work in the company have a very high experience in the field of cleaning in general, as well as we will give you cleanliness of the highest quality and the lowest prices with the testimony of customers, our goal is to satisfy our customers to the highest degree possible and thanks to God always First of all, thanks to the workers and technicians, we were able to satisfy all the customers who contracted with the company and contacted them, because we specialize in cleaning, sewerage and transport of luggage just contact us and you will notice that your house as if it is completely new from the intensity of cleanliness.
شركة الصفرات للتنظيف بالرياض
شركة الصفرات لتنظيف الخزانات بالرياض
شركة الصفرات لمكافحة الحشرات بالرياض
شركة الصفرات لنقل الاثاث بالرياض
شركة الصفرات لكشف التسربات بالرياض
شركة تنظيف بالمدينة المنورة
شركة تنظيف بينبع
https://www.cleanriyadh.com/

kayan web said...


The task of moving a catcher needs to rely on شركة نقل عفش بالمدينة المنورة It is specialized and has a long history in this field, helping it to carry out the task of transporting the baggage without causing any problems. Among the precautions taken by the company during transport of the luggage are the following: High-quality packaging materials to ensure that no problems are encountered during transport, the luggage is loaded into the car very carefully so as not to be subject to any problems during transportation. The luggage is re-connected to the place where it is transported and the packaging that is placed on the pallet is removed. During transportation. , All the transferred items are written to make sure that there is no defect in the piece, therefore you will ensure the transfer of the baggage without being exposed to any problems during transportation, شركة نقل اثاث بالمدينة المنورة .
Is characterized by شركة تنظيف بالمدينة المنورة With the experience and efficiency in the task of cleaning, as it uses the best equipment and the latest in addition to many aspects that focus on them to ensure that the cleaning is done to the fullest, and the most important things that you find in the fast service company and nowhere else find the following: It depends on the best detergents that can eliminate stains and smears, follow a certain system in the cleaning task; for this reason it ensures that it reaches the best results, depends on the latest methods such as steam cleaning method which proved its efficiency in the cleaning work, During which to eliminate all germs and The bacteria that are present in the place and maintain the health of the present, possess the best specialized perfumes that you can only find شركة نظافة بالمدينة المنورة.
that شركة تخزين اثاث بالمدينة المنورة It can store any quantity of furniture even if it is huge. This is because the company owns large warehouses divided into many sections. It packs and puts furniture in cars and is transported to the stores equipped with the highest level and has the latest means of monitoring. شركة تخزين عفش بالمدينة المنورة You will get satisfactory results without having to pay a lot of money in return
Be aware شركة تنظيف بينبع Cleaning works require the latest equipment for cleaning and the best detergents. This is what it provides to its customers. Therefore, it ensures the results. The company can clean any place, Will t D have شركة نظافة بينبع Discounts and offers can not be found elsewhere
The task of moving furniture from one place to another can not be done by anything, but it must rely on a specialized company such as شركة نقل اثاث بينبع ، As it will provide you with assurance that the furniture transfer works will be done well and will not be exposed any piece of the pieces to any problems during the transfer of furniture. In addition, it will carry out a comprehensive inspection of all parts before and before the transfer. The best packaging tools are used in this task. you only have to communicate with شركة نقل عفش بينبع .
Visit our website
https://www.zeenclean.com/

kayan web said...


شركة تنظيف بالمدينة المنورة Is one of the best companies currently located in Al Madinah Al Munawwarah, Saudi Arabia. Since the company started its activities more than twenty years ago, it has endeavored to develop all its services and made sure to provide the best service at the highest level of quality in cleaning and disinfection at the lowest prices possible. The company believes that the company's employment is a mirror that reflects the efficiency of the company that boasts of it. The worker must be confident and credible to provide the customer with everything he can provide. JAL cleaning and sterilization found in شركة تنظيف منازل بالمدينة المنورة .
شركة نقل اثاث بالمدينة المنورة Providing customers with transportation services of furniture and furniture and storage of furniture using the latest methods and methods and modern techniques and trained workers and freight cars specially equipped to transport furniture and clothes to anywhere inside or outside Medina, customers often need a city to transfer furniture to move furniture from their offices or homes Or their companies to new places but are afraid of their loss of damage or loss, but our company guarantees its customers to complete the transfer process safely and safely without being exposed to any piece of fracture or loss as the company provides a service to lift and download furniture using a hydraulic winch The only available within شركة نقل عفش بالمدينة المنورة .
شركة تنظيف بينبع The company's services include all kinds of services needed by customers such as house cleaning services, apartments, cleaning services for ground and upper water tanks, cleaning of palaces and cleaning services for hotels, residential complexes, mosques, parks, facilities and others. Types of Services The main governmental and private bodies cooperated with the cleaning company in Yanbu. Our company has provided them with the most complete image that has impressed them and increased their confidence in the skill and efficiency of our company and its employees. P safe and effective when providing various cleaning services such detergents, but inside there is no شركة تنظيف منازل بينبع .
شركة نقل اثاث بينبع Is one of the largest furniture transport companies in the city of Yanbu, which is known for providing services at the highest level and the company always offers offers and discounts and wonderful offers on the cost of services and this is what surprises customers and make them always put them the only choice for them, we have a professional team of carpenters who oversee the distinguished operations Dismantling and installing furniture and repair and maintenance of any fractures, as the company has workers polishing furniture and wooden furniture with effective polishes to remove the dirt from the layers of paint and make the furniture bright shiny like new, after the completion of cleaning the workers of evil Of furniture with materials encapsulates the strength and durability to protect the furniture from the external shocks or natural factors such materials are available only from within شركة نقل عفش بينبع
Visit our website
https://fajr-sate3.com/

kayan web said...

Due to the level of quality provided by our company Al-Safa Company in Al-Ahsa شركة تنظيف بالاحساء of cleaning and cleaning services of air conditioning and sewage and insect control on all household services that we do,شركة تنظيف مكيفات بالاحساء and taking our prices suitable for all segments of society, has become the best and most important company in the field of cleaning. شركة تنظيف خزانات بالاحساء In order to maintain our success and progress, the company strives to continue along the same lines, through continuous development and the constant pursuit of following all that is best for the masters of customers. شركة مكافحة حشرات بالاحساء So, never hesitate our dear customer to contact us if you want daily, weekly or monthly cleaning for your home, your garden or your company, شركة تسليك مجارى بالاحساء or even want any kind of cleaning services, we will promptly meet your request with perfect quality and low cost .
شركة الصفرات لكشف التسربات بالرياض
شركة الصفرات للتنظيف بالرياض
شركة الصفرات لتنظيف الخزانات بالرياض
https://www.al-safaa.com/

kayan web said...

شركة تنظيف فلل بالرياض Perfect cleaning and cleaning of the villa's rooms and the use of a vacuum cleaner to remove dust and soil.شركة تنظيف بالرياض The beauty and cleanliness of the place gives the use of steam cleaning machines that remove stains accurately and quickly and are used to clean canes and boards.
شركة تنظيف بالخرج Carpets, carpets and ceramics. If you are unable to execute these tips from شركة تنظيف منازل بالخرج .
شركة مكافحة الحمام بالرياض We provide you with a range of tips that prevent the nesting of the bathroom on the surface of your home you clean the surface and balconies from the remnants of the grain and clean it from waste and used furniture
شركة تنظيف منازل بالمدينة المنورة We have the ability to make your home an oasis of cleanliness and beauty. We have a dedicated team to clean every part of your home, but we are keen to provide important tips to keep your house clean for as long as possible. شركة تنظيف بالمدينة المنورة Use a vacuum cleaner to get rid of accumulated dust on a daily basis. Cleaning the glass home facades provides a perfect look for the home Provide you with a great service in cleaning your house if you can not do this hard work and effort شركة نقل عفش بالمدينة المنورة .
شركة تنظيف بينبع Provide you with a distinctive service in all types of private cleaning Carpet carpet cleaning using the steam cleaning machine makes it clean and fully sterile.
شركة نقل اثاث بينبع It is an ideal choice to carry out your home furniture without any effort or hardship. But if you want to do it yourself, arrange the clothing bags for your family so that you can remove the tires and wooden rooms easily. Transportation. Many things you can do .
شركة تنظيف منازل بمكة It is the best choice for you to clean the perfect parts of your home - Carpet cleaning and carpeting the best types of steam cleaning machines or sent to Cleaning and cleaning of beds and boards and putting mattresses on them to prevent the accumulation of dust and stains on them You must use high quality detergents to ensure high quality cleaning of all the items and parts of your home You need a daily cleaning of the kitchen and bathrooms to give a recovery and confidence in the cleanliness of the whole house شركة تنظيف خزانات بمكة Able to clean your home without bothering you or get tired at great cheap prices.
Visit our website
https://www.allsaad.com/

Post a Comment

Cron Design Studio: Dublin based web design & software development