Jonas
Jonas

Reputation: 1069

Overriding styles | JQuery

This code works fine here

http://jsfiddle.net/LH7sy/11/

It tries to find sml( and )sml in elements with the class uppercase and replace them with <span style="text-transform:none"> and </span>

but when I try to put all of that in one file, HTML file, it just won't work !

Should I use something else instead of $(document).ready ? What is wrong ?

<html>
<head>
<script type="text/javascript">
<!--
$(document).ready(function () {
     $('.uppercase').each(function() {
        var end = false;
        var s = $(this).html();
        while(end == false) {
            var p1 = s.indexOf('sml(');
            var p2 = s.indexOf(')sml');
            if (p1 != -1) { /* if '(' is found in the string */
                var result = s.substring(0,p1);
                result += '<span style="text-transform:none">';
                result += s.substring(p1+4,p2);
                result += '</span>'                        
                result += s.substr(p2+4);
                s = result;
            } else {
                end = true;
            }
        }
        $(this).html(result);
    })
})
-->
</script>

<style type="text/css">
<!--
.uppercase:hover {
    text-transform:uppercase;
}
-->
</style>
</head>
<body>

  <span class="uppercase">
     everything uppercase except sml(this)sml and sml(this too)sml
  </span>

</body>
</html>

Upvotes: 1

Views: 114

Answers (2)

bpeterson76
bpeterson76

Reputation: 12870

Style should really be up in the <head> of the document. You also need to ensure you're actually loading jQuery, which isn't specified in your code.

Upvotes: 1

ThinkingStiff
ThinkingStiff

Reputation: 65341

You need to include a reference to jQuery before your document.ready call:

<script type='text/javascript' src='http://code.jquery.com/jquery-1.7.1.js'></script>

Upvotes: 1

Related Questions