Hello programmers. I have some lines code that should be converted into pure javascript code. Here is the code that should be converted: var site_url='http://mysite.com/';$(document).ready(function(){GenerateAds();});function GenerateAds() {$response=[];$(".buysiteads-ad").each(function(index){$widget=$(this);$id=$widget.data('id');$type=$widget.data('type');$size=$widget.data('size');$widget.html('Loading...');$widget.css('position','relative');$params='id='+$id+'&type='+$type+'&size='+$size;send($widget,$params,$type);});} function send($widget,$params,$type) {$.getJSON(site_url+'api/'+$type+'/?callback=?',$params,function(data){jsonParse($widget,data.html,$type);});} function jsonParse($widget,html,$type){$widget.html(html);} Code (markup): Please message me if you can do it.
Try cutting out some of the other functions. $(document).ready(function () { var site_url = 'http://mysite.com/'; $response = []; $(".buysiteads-ad").each(function (index) { $widget = $(this); $id = $widget.data('id'); $type = $widget.data('type'); $size = $widget.data('size'); $widget.html('Loading...'); $widget.css('position', 'relative'); $params = 'id=' + $id + '&type=' + $type + '&size=' + $size; $.getJSON(site_url + 'api/' + $type + '/?callback=?', $params, function (data) { $widget.html(data.html); }); }); }); Code (JavaScript): changed from: var site_url = 'http://mysite.com/'; $(document).ready(function () { GenerateAds(); }); function GenerateAds() { $response = []; $(".buysiteads-ad").each(function (index) { $widget = $(this); $id = $widget.data('id'); $type = $widget.data('type'); $size = $widget.data('size'); $widget.html('Loading...'); $widget.css('position', 'relative'); $params = 'id=' + $id + '&type=' + $type + '&size=' + $size; send($widget, $params, $type); }); } function send($widget, $params, $type) { $.getJSON(site_url + 'api/' + $type + '/?callback=?', $params, function (data) { jsonParse($widget, data.html, $type); }); } function jsonParse($widget, html, $type) { $widget.html(html); } Code (JavaScript):
@tejli007 you're misunderstanding the difference between a framework and a library. A framework (e.g. AngularJS) is the one that gives you other "methods" to achieve the same result which you could achieve with pure JS , while a library like jQuery gives you the ability to achieve the same result via JS's methods but with less code. A framework takes time to initialize all its components. The difference we are talking about here in your example, would have a visible impact when you do like five hundred widgets per instance. This is not the case, and the difference is around few miliseconds which isn't visible for the user because of the browser page rendering process.