javascript selecting style tags?
I thought that you could select a style element by doing:
<style id="mystyle"></style>
And then
$('#mystyle').remove()
But no go. How do I select the style in 开发者_运维技巧js?
Thanks.
The style element can't have an id
attribute, according to the spec.
<!ELEMENT STYLE - - %StyleSheet -- style info -->
<!ATTLIST STYLE
%i18n; -- lang, dir, for use with title --
type %ContentType; #REQUIRED -- content type of style language --
media %MediaDesc; #IMPLIED -- designed for use with these media --
title %Text; #IMPLIED -- advisory title --
>
Source.
However, in practice, browsers generally let you get away with these things. Their implementations may be different though.
Have you considered selecting it via another means? What about $('head style:eq(1))
.
try this:
$('style[id=mystyle]').remove()
Seems to work fine in Firefox 4.x ...
Live Demo
$('#mystyle1').remove();
$('style[id=mystyle2]').remove();
document.body.removeChild(document.getElementById('mystyle3'));
Maybe you could try this workaround?
$("head").find("#mystyle")
Or alternatively, go back to basics and use old school javascript:
document.getElementById("mystyle")
精彩评论