rakop rakop - 2 years ago 97
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?

Answer Source

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().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download