Click here to Skip to main content
14,298,693 members
Rate this:
Please Sign up or sign in to vote.
<script language= "javascript">
window.addEventListener('load', onDocLoaded, false);

        function onDocLoaded(evt)
 { var element=document.getElementById("tgtP");
element.addEventListener('click', convert, false);}
function convert()
{
   var a=document.getElementById("tgtP").innerText;
   var b="";
   for (i = 0; i < a.length; i++)

   {

          if (a.charCodeAt(i) >= 65 && a.charCodeAt(i) <= 90)

           {

                 b = b + a.charAt(i).toLowerCase();

           }

          else{

                 b = b + a.charAt(i).toUpperCase();

           }

    alert(b);

        }}

    </script>
Posted
Updated 9-Sep-19 21:35pm
Comments
ZurdoDev 28-Jan-15 11:29am
   
jQuery is JavaScript so there is no real reason to convert one to the other unless you just want to.

Where are you stuck?
Sergey Alexandrovich Kryukov 28-Jan-15 11:42am
   
First, the whole "convert" notion is total nonsense, because jQuery is Javascript.
If you simply want to utilize jQuery, the question is: what have you tried so far?
—SA
Rate this:
Please Sign up or sign in to vote.

Solution 1

Yes,I want to utilize jQuery, but I don't know how write in jQuery function onDocLoaded
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

jQuery is JavaScript library with many pre-built functions that you can plug and use resulting in "Write Less Do More". However, you have to learn to use it. Visit http://www.w3schools.com/jquery/[^].
To answer your question about conversion:
document.getElementById("tgtP") 

is expressed as =>
$("#tgtP")

in jQuery syntax.
innerText

=>
text();

window.addEventListener('load', onDocLoaded, false)

=>
$(document).ready(function(){
    // to code here
});

Go through the tutorial and you will understand them. The resulted script in jQuery will be:
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
    var element = $("#tgtP");
    var a = element.text();
    var b="";
    element.click(function(){
       for (i = 0; i < a.length; i++)
       {
          if (a.charCodeAt(i) >= 65 && a.charCodeAt(i) <= 90)
           {
                 b = b + a.charAt(i).toLowerCase();
           }
          else
           {
                 b = b + a.charAt(i).toUpperCase();
           }
           alert(b);
        }
    });
});
</script>
</head>
<body>
<p id="tgtP">aBc dEf ghIK kl</p>
</body>
</html> 
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100