If you need to only target the first instance of the h1, you may want to use these styles instead:
h1 { color: green }
h1:first-child { color: red }
The following are some options for dominating one style over another. Which may or may not be what you want to do here. It's a little unclear.
There are several different options you can pursue. Because you say you don't want to use classes or IDs to accomplish this, I'll leave those out. Otherwise, you would be able to just use a class, or several classes to dominate the h1's style.
Load later
Without understanding the circumstances that make you want to use jQuery's load()
to add a CSS file, if this must be, you could simple do this after the style tags.
<body onLoad="ext()">
<style>
h1 {
color:green;
}
</style>
<script>
function ext() {
$('#aaa').load('external.txt');
}
</script>
That being said, can I recommend a better way to do this other than just using <link.../>
? Again, I don't know the context, but if you must use JavaScript to do this...
<body>
<style>
h1 { color: red; }
</style>
<script>
var myStyle = document.createElement('link')
myStyle.rel = "stylesheet"
myStyle.href = "external.css"
document.body.appendChild(myStyle)
</script>
</body>
You can put this anywhere, it will automatically insert external.css before the ending </body>
tag, giving it precedence with equal selectors.
Increased specificity
body h1 {
color: green;
}
By specifying h1 is a child of whatever parent you find handy, you've effectively made your selector more specific without using classes or IDs.
!important Attribute
I hate to use this, much less recommended, but it anoints your CSS with last-word privleges.
h1 {
color: green !important;
}
No other CSS can override this. Make sure the !important
comes before the ;
.