rakop rakop - 10 months ago 46
Javascript Question

writing javascript in html page

I found JavaScript I like to use but I need It to be written in the html page and not as a separate file ... Here is a JS fiddle

Here is how I tried to write it:

p span {color:blue;}


<p>sony sensor 2.1mp</p>

$('p').html(function(index, value) {
return value.replace(/(\d+)/g, '<span>$1</span>');


I know that I can wrap the numbers with
tag but
in my actual page I have numbers dozens of times during the text and this is way I rather use the script...

What do I need to change in the script to make it work?


Two things, use <script type='text/javascript'></script>. And add a reference to jQuery library.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>

and put your scripts inside $(document).ready().