There are several ways to unload CSS and JS scripts that have already been applied by using Javascript or JQuery. To unload CSS is simpler than JS because for JS it depends on whether the JS has been triggered and if it has already altered the DOM with it' payload, because once the DOM is altered, disabling the JS might not return the DOM it to it's original state, if that is not a problem do not worry.
You must follow the rules below:
Depending on what type of scripting language you use, Javascript/JQuery, to unload the CSS or JS there are different ways of referencing the elements.
You can access the relevant element by:
Identifiers
These are different identifiers you can use in the following codes to basically identify which file or element you want to work on. There might be more and should be easy to experiment with:
The points at which I can activate the unload script:
If using jQuery you must run the script after you load the jQuery library.
Although these are all written for CSS, the commands should work for Javascript script calls. These scripts will not run unless they are run after the page has loaded the JQuery library.
" and ' can be interchanged but i prefer to use " for normal HTML declarations. This keeps things easy to understand.
These changes will be applied to the DOM so when you are looking at the source of the page you might not see them, it depends on the browser. If in doubt use the Web Developer Toolbar in Firefox and select View Generated Source and you will see the source code with all changes applied by the javascript.
It is important to use .prop, not .attr. If you use .attr, the code will work in some browsers, but not Firefox. This is because, according to MDN, disabled is a property of the HTMLLinkElement DOM object, but not an attribute of the link HTML element. Using disabled as an HTML attribute is nonstandard.
Disable CSS
$('link[href="mycustom.css"]').prop('disabled', true);
This will disable the mycustom.css although for most purposes the CSS file has been removed, but this CSS file can be re-enabled. When you look at the generated souce you will see that the link for mycustom.css is still present butthe styling is not applied.
Re-Enable CSS
$('link[href="mycustom.css"]').prop('disabled', false);
Re-enable a mycustom.css CSS file.
Remove CSS
$('link[href="mycustom.css"]').remove();
This will completely remove the the mycustom.css from the DOM, the page will need to be refreshed without this script on it to load the CSS file. when you look at the generated source code you will see a blank line where the mycustom.css link use to be, almost like a placeholder.
Insert CSS
$('head').append('<link href="/mycustom.css" rel="stylesheet" id="newcss" />');
This command will insert the mycustom.css CSS file into the header. The id="newcss" is optional but can be useful.
Insert CSS 2
This is another version to insert a CSS file from - How to load CSS stylesheets dynamically with jQuery | Vidal Quevedo
$('head').append($('<link rel="stylesheet" href="/mycustom.css" type="text/css" media="screen" />'));
This command will insert the mycustom.css CSS file into the header. The instructions are simple and well layed out but I dont know why there is a second $().
joomla has JQuery inbuilt which makes things easier
I have the need to remove a CSS file (jsn_ext_k2.css) from joomla on a single page but without altering any core code or extension. So I will need to do this by an inline script as i do not want to load the script site wide.
noConflict()
Joomla runs JQuery in noConflict() mode because it uses other libraries so instead of calling a function with a $() you should use jQuery() , make note of the capitalised Q.
Joomla loads the noConflict() from http://yoour-joomla-site.com/media/jui/js/jquery-noconflict.js
If you do not use the correct format for the jQuery function you are likely to see either of the following errors:
The CSS is called by the following:
<link rel="stylesheet" href="/templates/jsn_time_pro/ext/k2/jsn_ext_k2.css" type="text/css" />
I have removed the CSS file by using the following inline code:
<script type="text/javascript"> jQuery('link[href="/templates/jsn_time_pro/ext/k2/jsn_ext_k2.css"]').remove(); </script>
This Also works but by disabling the CSS file
<script type="text/javascript"> jQuery('link[href="/templates/jsn_time_pro/ext/k2/jsn_ext_k2.css"]').prop('disabled', true); </script>
Things i have used:
document.getElementsByTagName('link')[0].disabled = true;
$("link[href='fileToRemove.css']").remove();
var firstLink = document.getElementsByTagName('link')[0]; firstLink.parentNode.removeChild(firstLink)
I have a css file in my <head> tag, defined as follows:
<link href="/foo/bar/baz.css" rel="stylesheet" class="lazyload" type="text/css">
I want to be able to remove this css file dynamically, from the javascript. However, at runtime, I won't have the full href available, only the baz.css part (That's because the file is hosted at a CDN, and the url can be dynamically generated / different each time, so it can't be hard-coded).
$("link[href*='baz']").prop('disabled', true); $("link[href*='baz']").remove();
To cater for ie you have to set the stylesheet to be disabled as it keeps the css styles in memory so removing the element will not work, it can also cause it to crash in some instances if I remember correctly.
This also works for cross browser.
document.styleSheets[0].disabled = true; //so in your case using jquery try $('link[title=mystyle]')[0].disabled=true;
These days, the "jQuery way" would look like
$('link[title=mystyle]').prop('disabled',true);
I managed to do it with:
$('link[title="mystyle"]').attr('disabled', 'disabled');
it seems this is the only way to remove the styles from memory. then I added:
$('link[title="mystyle"]').remove();
to remove the element too.
To disable your selected stylesheet:
$('link[title="mystyle"]').prop('disabled', true);
If you never want that stylesheet to be applied again, you can then .remove() it. But don’t do that if you want to be able to re-enable it later.
To re-enable the stylesheet, do this (as long as you didn’t remove the stylesheet’s element):
$('link[title="mystyle"]').prop('disabled', false);
In the code above, it is important to use .prop, not .attr. If you use .attr, the code will work in some browsers, but not Firefox. This is because, according to MDN, disabled is a property of the HTMLLinkElement DOM object, but not an attribute of the link HTML element. Using disabled as an HTML attribute is nonstandard.
To remove a stylesheet:
$('link[src="<path>"]').remove();
To Replace a stylesheet:
$('link[src="<path>"]').attr('src','<NEW_FILE_PATH>');
no jQuery solution
if you can add id to your link tag
<link rel="stylesheet" href="/css/animations.css" id="styles-animations"> document.getElementById("styles-animations").disabled = true;
if you know index position of your css file in document
document.styleSheets[0].disabled = true; // first document.styleSheets[document.styleSheets.length - 1].disabled = true; // last
if you want to disable style by name you can use this function
/** * @param [string] [styleName] [filename with suffix e.g. "style.css"] * @param [boolean] [disabled] [true disables style] */ var disableStyle = function(styleName, disabled) { var styles = document.styleSheets; var href = ""; for (var i = 0; i < styles.length; i++) { href = styles[i].href.split("/"); href = href[href.length - 1]; if (href === styleName) { styles[i].disabled = disabled; break; } } };
note: make sure style file name is unique so you don't have "dir1/style.css" and "dir2/style.css". In that case it would disable only first style.
Give an id to the <link> tag.
<link rel="stylesheet" href="/style1.css" id="style1" /> <link rel="stylesheet" href="/style2.css" id="style2" />
And use this code:
$("#A").click(function(){ $("#style1").attr("disabled", "disabled"); });
Note: While there is no disabled attribute in the HTML standard, there is a disabled attribute on the HTMLLinkElement DOM object.
The use of disabled as an HTML attribute is non-standard and only used by some Microsoft browsers. Do not use it. To achieve a similar effect, use one of the following techniques:
You can unload a css by disabling it as follows:
$("#A").click(function(){ $("link[href*=bb.css]").attr("disabled", "disabled"); $("link[href*=cc.css]").attr("disabled", "disabled"); $("link[href*=aa.css]").removeAttr("disabled"); });
Is there a way to dynamically remove the current stylesheet from the page?
For example, if a page contains:
<link rel="stylesheet" type="text/css" href="http://..." />
Assuming you can target it with jQuery it should be just as simple as calling remove() on the element:
$('link[rel=stylesheet]').remove();
That will remove all external stylesheets on the page. If you know part of the url then you can remove just the one you're looking for:
$('link[rel=stylesheet][href~="foo.com"]').remove();
According to this question, just removing the link element is not enough. You should make it disabled first, with .prop('disabled', true). Though it’s possible that browsers have changed since that question was written (2010), and you don’t need to disable the link
If you know the ID of the stylesheet
use the following. Any other method of getting the stylesheet works as well, of course. This is straight DOM and doesn't require using any libraries.
sheet = document.getElementById(styleSheetId) sheet.parentNode.removeChild(sheet)
For the purpose of this article these information blocks have been put together into one but you can seperate them in to sperate entities and put them in individual module positions.
Our rooms are comfortable with mod-cons including the important TV and kettle for the end of a relaxing day.
Enjoy your stay and leave the stresses of the modern life behind you for your stay. The Lake District is a beautiful area to unwind.
What better way to start the day than with a Traditional English Breakfast.
HTML
<div id="information-blocks-container"> <div style="float: left;"> <h3>Our Rooms</h3> <div> <div> <div class="align-left"><img src="/images/kb/2015/663/bed.png" alt="bed" style="margin: 5px;" /></div> <div class="align-right"> <p style="width: 185px; margin-top: 0;">Our rooms are comfortable with mod-cons including the important TV and kettle for the end of a relaxing day.</p> </div> </div> <div class="clearbreak"> </div> </div> </div> <div style="float: left;"> <h3>Relax</h3> <div> <div> <div class="align-left"><img src="/images/kb/2015/663/clock.png" alt="clock" style="margin: 5px;" /></div> <div class="align-right"> <p style="width: 185px; margin-top: 0;">Enjoy your stay and leave the stresses of the modern life behind you for your stay. The Lake District is a beautiful area to unwind.</p> </div> </div> <div class="clearbreak"> </div> </div> </div> <div style="float: left;"> <h3>English Breakfast</h3> <div> <div> <div class="align-left"><img src="/images/kb/2015/663/bulls-eye-eggs-with-toast-and-bacon.png" alt="bulls eye eggs with toast and bacon" style="margin: 5px;" /></div> <div class="align-right"> <p style="width: 185px; margin-top: 0;">What better way to start the day than with a Traditional English Breakfast.</p> </div> </div> <div class="clearbreak"> </div> </div> </div> </div>
These are the emails BT will send to their customers who want to transfer their domain away from them.
Dear xxxxxxx
Account Number: xxxxxxx
Domain names: xxxxxxxx
Please can you confirm you wish to transfer the above domain names by filling in the information below and replying to btdhelp@bt.com
Please contact your new host provider and ask them for the information detailed in the bullet points below, this information is needed to start the transfer process.
- New IPS Tag:
- Who you are transferring to:
Before you request this transfer, please be aware:
- You will lose any exposure we are achieving for you on the internet, this includes directory listings and search engine rankings.
- Any email facilities provided either by forwarding or attached to any domains will be lost.
- We will no longer be responsible for renewing your domain name.
- We do not accept liability for any loss of business or enquiries as a result of this transfer request.
You may not be fully aware of what we are achieving for you on the internet and what options you have available with this domain name. If you would like to discuss this without further obligation, please call our support team on 0800 800 891.
We look forward to hearing from you.
Kind Regards,
Ewan xxxxxx
BT Marketing SolutionsThis email contains BT information, which may be privileged or confidential.
It's meant only for the individual(s) or entity named above.
If you're not the intended recipient, note that disclosing, copying, distributing or using this information is prohibited.
If you've received this email in error, please let us know immediately on the email address above.
We monitor our email system, and may record your emails.British Telecommunications plc
Registered office: 81 Newgate Street London EC1A 7AJ Registered in England no: 1800000
Dear xxxxxxx
Account Number: xxxxxxx
Domain names: xxxxxxxx
Please can you confirm you wish to transfer the domain name by replying to btdhelp@bt.com and confirming your request. Please also advise where you are wishing to transfer the domain to.
Once we have received your written confirmation, your domain name will be unlocked and an authorisation code will be sent to the email address we have stored on the registered data for the domain
Before you request this transfer, please be aware:
- You will lose any exposure we are achieving for you on the internet, this includes directory listings and search engine rankings.
- Any email facilities provided either by forwarding or attached to any domains will be lost.
- We will no longer be responsible for renewing your domain name.
- We do not accept liability for any loss of business or enquiries as a result of this transfer request.
You may not be fully aware of what we are achieving for you on the internet and what options you have available with this domain name. If you would like to discuss this without further obligation, please call our support team on 0800 800 891.
We look forward to hearing from you.
Kind Regards,
Ewan xxxxxx
BT Marketing SolutionsThis email contains BT information, which may be privileged or confidential.
It's meant only for the individual(s) or entity named above.
If you're not the intended recipient, note that disclosing, copying, distributing or using this information is prohibited.
If you've received this email in error, please let us know immediately on the email address above.
We monitor our email system, and may record your emails.British Telecommunications plc
Registered office: 81 Newgate Street London EC1A 7AJ Registered in England no: 1800000
When the client has supplied us with the EPP code and we have started the process the following steps will occur.
Although these instructions are written for a .com address they will most likely apply to all other domain transfers except .co.uk
These instructions are written for us and our registrar is eNom so not everybody will get the steps 2 -3 which are from eNom. Different registrars might have something similiar but i dont believe it is mandatory.
1 - 18-03-15 10:37
Receipt of the Authentication code which is then supplied to us.
From : no-reply@internetters.co.uk Date : 18/03/2015 - 10:37 (GMTST) To : bob.builder@clientdomain.com Subject : Auth code for trexxxxxxxxxxxxxire.com Further to your request, the auth-code for trexxxxxxxxxxxxxire.com is: #ZZI861^54>'[2. If you require assistance, please visit http://helpdesk.internetters.co.uk or call +44.370 056 6700. Regards Internetters Ltd
2 - 20-03-15 23:56
An email from eNom that says the have received a transfer request for the client's domain and that they need to click on the link and follow the instructions.
From : info@transfer-approval.com Date : 20/03/2015 - 23:56 (GMTST) To : bob.builder@clientdomain.com Subject : Domain Transfer Request for trexxxxxxxxxxxxxire.com STANDARDIZED FORM OF AUTHORIZATION DOMAIN NAME TRANSFER - Initial Authorization for Registrar Transfer Attention: Joxxxxxxxxxxxxxtors Re: Transfer of trexxxxxxxxxxxxxire.com eNom, Inc. has received a request from John Baird (Joxxxxxxxxxxxxxtors) on 20 Mar 2015 to become the new registrar of record. You have received this message because you are listed as the Registered Name Holder or Administrative contact for this domain name in the WHOIS database. Please read the following important information about transferring your domain name: * You must agree to enter into a new Registration Agreement with us. You can review the full terms and conditions of the Agreement at < http://transfer-approval.com/u.asp?id=86C1EA39-7FF9-4F8D-A891-9B2D1B9D5B90 > * Once you have entered into the Agreement, the transfer will take place within five (5) calendar days unless the current registrar of record denies the request. * Once a transfer takes place, you will not be able to transfer to another registrar for 60 days, apart from a transfer back to the original registrar, in cases where both registrars so agree or where a decision in the dispute resolution process so directs. If you WISH TO PROCEED with the transfer, you must respond to this message by using the following URL (note if you do not respond by 27 Mar 2015, trexxxxxxxxxxxxxire.com will not be transferred to us): < http://transfer-approval.com/u.asp?id=86C1EA39-7FF9-4F8D-A891-9B2D1B9D5B90 > YOU MUST CLICK THIS LINK TO CONTINUE THE TRANSFER PROCESS If you DO NOT WANT the transfer to proceed, then don't respond to this message. If you have any questions about this process, please contact info@mustbemedia.co.uk.
3 - 20-03-15 16:45
This is the page that is loaded from the link in the first email and it basically is asking the client if they want to transfer their domain or cancel the process.
4 - 20-03-15 16:45
After approving the transfer with eNom on the previous step the client will now see a confirmation message on-screen.
5 - 21-03-15 14:17
eNom has now contacted the loosing registrar which in turn has sent the client an email requesting confirmation that they approve the transfer. The client needs to click on the link to finish the last part of the transfer with their current registrar.
From : transfers@internetters.co.uk Date : 21/03/2015 - 18:21 (GMTST) To : bob.builder@clientdomain.com Subject : Transfer Away request has been received for the domain treesurgeonsayrshire .com An English version of this message is contained below. Attention: bob.builder@clientdomain.com Re: Transfer of trexxxxxxxxxxxxxire.com Iomart received notification on Sat Mar 21 14:17:06 2015 that you have requested a transfer to another domain name registrar. If you want to proceed with this transfer, you do not need to respond to this message. If you wish to cancel the transfer (or to approve it immediately), please contact us before Thu Mar 26 14:17:06 2015 by going to our website, https://transfers.internetters.com/index.cgi?away=1&domain=trexxxxxxxxxxxxxire.com&id=r8q2UUzJWf to confirm. You may need to enter the following information to complete the transfer: Domain Name: trexxxxxxxxxxxxxire.com Transfer Key: r8q2UUzJWf If we do not hear from you by Thu Mar 26 14:17:06 2015, the transfer will proceed. If you have any queries at any time, please contact our Support Team via our helpdesk, where you can also search our extensive knowledge base for advice on using the control panel and our extensive range of web packages. The helpdesk can be accessed via your control panel or you can call our Support Team on +44.370 056 6700, Monday to Friday 9am - 5.30pm. Regards Internetters Support
6 - 21-03-15 18:21
Once the client has clicked on the link they are presented with the following question. They obviously need to select to approve the transfer.
7 - 22-03-15 18:35
Once the Client has approved the transfer with their loosing registrar they will be presented with the following message confirming the transfer will now go ahead and that they will be transfered to the registrar, in this case eNom.
To transfer out a domain (which is not a .co.uk) you need to supply your client with an EPP code which they then give to their new registrar. When you click the Get EPP Code button in WHMCS you get the following message:
The client will now receive a valid EPP code for the relevant domain. This EPP code will expire it is either valid for 24hr, 48hr or 7 days but I am not sure which.
These transfers will use an EPP code to facilitate the transfer of a domain between registrars and is quite safe.
Answer ID 246 - How to Initiate an Incoming Domain Transfer?
To transfer a domain into our system, you will need to do three things on the current registrar's system (for most domain extensions):
Please note that some domain extensions don't use Registrar-Lock or authorization codes. For example, .eu domains only use email verification for transfers, and don't need to be unlocked or have an authorization code submitted for the transfer. If you are having trouble completing any of the above steps, please search our knowledgebase for specifics on the domain extension that you are trying to transfer, or submit us a ticket with your request.
For specific instructions on how to complete the above steps in the current registrar's system, please see our Domain Name Transfer Help Section.
For specific on .UK transfers, please see the article, Answer ID 362 - How to Transfer a .UK Domain?
Once you have the necessary information, please do the following to submit the incoming transfer request in our system:
If you're using the Auto-Verification method, in most cases, either our system or the registry will send you an email to approve or reject the transfer. Once you respond affirmatively to the email, the transfer process will go forward.
For information on transfer timeframes, please see the article, Transfers - Timeframe to complete.
For information on transfer restrictions, please see the article, Reasons a transfer could be rejected.
If your domain expired and you renewed it with your current registrar during the expiration grace period, you may want to wait until 46 days after the expiration date to transfer your domain to avoid losing one year of registration. Please see this article for further details: Transfers - extra year missing after transfer completed.
Answer ID 234 - How to Initiate an Outgoing Domain Transfer?
Transferring your domain to another registrar is different than changing your nameservers, or "transferring your domain to your hosting company." Please see the article, How to change domain nameservers (DNS) for further information. Please give us a call or submit us a ticket if you have any questions.
If you choose to work with a different registrar and need to transfer your domain registration away from us, you will need to do three things on our system (for most domain extensions):
Please note that some domain extensions don't use Registrar-Lock or authorization codes. For example, .eu domains only use email verification for transfers, and don't need to be unlocked or have an authorization code submitted for the transfer. For such domain extensions, the below instructions may not be entirely applicable. If this is the case, please search our knowledgebase for specifics on the domain extension that you are trying to transfer, or submit us a ticket with your request.
For information on transfer timeframes, please see the article, Transfers - Timeframe to complete.
For information on transfer restrictions, please see the article, Reasons a transfer could be rejected.
If your domain expired and you renewed it with us during the expiration grace period, you will want to wait until 46 days after the expiration date to transfer your domain to avoid losing one year of registration. Please see this article for further details: Transfers - extra year missing after transfer completed. If your domain auto renews while in pending transfer status, the transfer will be cancelled. Therefore it is recommended that the auto-renewal setting be disabled prior to transfer. Enable/Disable Auto Renew for Domains
Note: eNom's DNS services are provided at no cost while your domain is registered with eNom. If your domain is utilizing our DNS services, and is transferred away to another registrar, you would need to purchase DNS hosting. Your domain will not continue to resolve to our name servers once it has been transferred away from the eNom credential and marked as transferred away within our database.
If you do not have a direct account with us please contact your reseller to obtain this information. If you do not know the name of your reseller, please see the instructions in the article, Who is my reseller?.
How do I transfer a .co.uk or .org.uk domain? What is involved in a .co.uk or .org.uk transfer?
Please note that .UK domains don't use authorization codes (EPP).
These instructions are based on Answer ID 362 - How to Transfer a .UK Domain?
Transferring .UK domains into our system is a two step process. Please do the following:
It does not matter the order in which the steps are completed, however, if you initiate the transfer with eNom first, you must submit the request to the losing registrar within one week. If initiating the request to the losing registrar first, you must initiate your transfer with eNom by either the 8th of current month or the 8th of the following month, whichever is closest to the current date.
What fees are involved?
At the time the transfer order is submitted in our system, we will reserve funds for the 2 year renewal price. The registry requires 2 year renewals for applicable transfers. There are two possible scenarios:
For further information on the reservation of funds, please see the article, INCOMING Domain Transfers - Are there fees if the transfer fails?.
For current transfer prices, please see the article, What prices do you charge for domain names and services? Where can I view my pricing?.
Transferring .UK domains away from our system is a two step process. Please do the following:
It does not matter the order in which the steps are completed, however, if you initiate the transfer with the gaining registrar first, you must submit the ticket within one week. If submitting the TAG change request with us first, you must initiate your transfer with the gaining registrar by either the 8th of current month or the 8th of the following month, whichever is closest to the current date.
Answer ID 243 - How do I push a domain to another account or sub-account?
To push a currently registered domain into another account:
To push an EXPIRED domain or MULTIPLE domains:
Incoming to eNom
Outgoing from eNom
In order to Test your Integration in our Sandbox, you need a Sandbox Account.
Please Note that you can’t use the API Credentials from our live site in our sandbox and likewise!
If you don’t have a Sandbox Account yet, you need to create one.
Please Note that you can’t use the API Credentials from our live site in our sandbox and likewise!
Links