Home » Blog » Beginner » Using jQuery to Delete All Inline HTML Styling

Using jQuery to Delete All Inline HTML Styling

Inline HTML styling (when the fashion attributes for a specific aspect are written inside the HTML tag) is just not one thing that’s thought-about a greatest apply when it comes to HTML and CSS, and it’s turning into much less and fewer widespread. You don’t typically come throughout inline styling until a website’s code hasn’t been touched because the 90s or early 2000s, however it’s definitely not remarkable. If you end up making an attempt to do a redesign of an older website that incorporates inline styling inside the HTML, you’ll virtually completely discover that overriding the inline styling could be a large ache.

Quite than undergo each HTML file to take away inline styling, all your inline styling woes could be eradicated utilizing a quite simple jQuery code snippet, which can utterly eliminate all the fashion attributes that may be discovered inside your HTML tags. To see the way it works, check out the code snippet under:

$("*[style]").attr("fashion", "");

The code snippet above makes use of jQuery to choose each single fashion attribute (utilizing the * selector together with the [style] attribute) and, utilizing the .attr technique, removes all the values from the inline type parts by changing the textual content with nothing (thanks to these empty citation marks).

This can be a tremendous easy answer to eliminating inline styling that may prevent tons and tons of time and aggravation. In case you’re engaged on a smaller website with much less situations of favor attributes inside the HTML tags, then it could be wiser to simply undergo and take away them manually, however when you’ve received an enormous measurement with inline styling on each single web page, then this can be a nice, tremendous simple, and fairly light-weight answer that may simply and shortly take away each single occasion of inline fashion attributes in order that the location in query might be up to date to look its easiest.