Click here to Skip to main content
15,891,006 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
var v = $(".pac-container .pac-item:first").text(inputAdd.value);
var firstResult =$(".pac-container .pac-item:first").text();
Posted
Comments
Mohibur Rashid 23-Mar-15 5:53am    
Its in javascript.
Santosh K. Tripathi 23-Mar-15 6:29am    
duplicate entry.

http://www.codeproject.com/Questions/889491/How-can-I-write-this-in-javascript?arn=5
Peter Leow 23-Mar-15 6:40am    
no more.

1 solution

jQuery is one of many JavaScript libraries. So it is essentially JavaScript. jQuery is optimized, lightweight, cross broswer and promote "write less do more". Take the second statement of your code as an example:
var firstResult =$(".pac-container .pac-item:first").text();

To reverse-engineer it in JavaScript would look like this:
C#
var parent = document.getElementsByClassName("pac-container");
// assume there is only one element with class name = "pac-container"
for (var i = 0; i < parent[0].childNodes.length; i++) {
    if (parent[0].childNodes[i].className == "pac-item") {
         firstResult = parent[0].childNodes[i].innerText;
         break;
    }
}

So there is really no reason to reverse engineer except for some academic exercises, may be.
Read more: https://blog.udemy.com/jquery-vs-javascript/[^]
 
Share this answer
 
v3

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