Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
1.44/5 (3 votes)
XML
<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 8-Feb-23 17:47pm
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

1 solution

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> 
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900