view raw
R Ganesh R Ganesh - 6 months ago 45
Ajax Question

need help in linking with wikipedia viewer

when i click the heading i want to go to relevant wikipedia article.i tried the wrap method.But it isn't happening.please help.
Here is the code.

if(e.which == 13)


function getData()
$('.title ,.card').remove();
var searchQuery = $('#search_box').val();
$.getJSON(''+searchQuery+'&utf8&callback=?', function(data){
var query =;

for(var i=0;i<query.length;i++)

**$('<div class="title">'+query[i].title+'</div>').addClass('title').wrap('<a href=""'+encodeURIComponent(query[i].title)+'"> </a>').appendTo('body');**




And here is a link to my pen.


You can use .wrapInner() method to wrap link inside div element

$('<div class="title"></div>')
.wrapInner("<a href='"+encodeURIComponent(query[i].title)+"'>"+query[i].title+"</a>")

in your .wrap() method your link doesn't have any value.

.wrap('<a href="'+encodeURIComponent(query[i].title)+'"> </a>')

Add query[i].title value to link. And with wrapInner() wrap that link around the <div class="title"> content

Check working code: codePen