Click here to Skip to main content
15,569,845 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 2hrs 5mins ago
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

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
var subjectObject = {
"Front-end": {
"HTML": ["Links", "Images", "Tables", "Lists"],
"CSS": ["Borders", "Margins", "Backgrounds", "Float"],
"JavaScript": ["Variables", "Operators", "Functions", "Conditions"]
},
"Back-end": {
"PHP": ["Variables", "Strings", "Arrays"],
"SQL": ["SELECT", "UPDATE", "DELETE"]
}
}
window.onload = function() {
var subjectSel = document.getElementById("subject");
var topicSel = document.getElementById("topic");
var chapterSel = document.getElementById("chapter");
for (var x in subjectObject) {
subjectSel.options[subjectSel.options.length] = new Option(x, x);
}
subjectSel.onchange = function() {
    //empty Chapters- and Topics- dropdowns
    chapterSel.length = 1;
    topicSel.length = 1;
//display correct values
for (var y in subjectObject[this.value]) {
topicSel.options[topicSel.options.length] = new Option(y, y);
}
}
topicSel.onchange = function() {
    //empty Chapters dropdown
    chapterSel.length = 1;
//display correct values
var z = subjectObject[subjectSel.value][this.value];
for (var i = 0; i < z.length; i++) {
chapterSel.options[chapterSel.options.length] = new Option(z[i], z[i]);
}
}
}
 
Share this answer
 

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