davidrguez31
New Member
I downloaded a livesearch JavaScript plugin for my site, it's working, but I need help to modify it a little bit.Here is the code:\[code\] $.ajax({url: $('base').attr('href') + 'index.php?route=product/search/ajax&keyword=' + keywords, dataType: 'json', type: 'GET', success: function(result) { if( result.length > 0 ) { var eList = document.createElement( 'ul' ); eList.id = 'livesearch_search_results'; var eListElem; var eLink; var eHref; for( var i in result ) { eListElem = document.createElement( 'li' ); eLink = document.createElement( 'a' ); if( result.img != null ) { var eImg = document.createElement( 'span' ); eImg.className = "img_container"; var img = new Image(); img.src = http://stackoverflow.com/questions/13731121/result.img; eImg.appendChild( img ); } else { eImg = document.createElement('span' ); eImg.innerHTML = ' '; } eDiv = document.createElement( 'div' ); eLink.appendChild( document.createTextNode(result.name) ); if( typeof(result.href) != 'undefined' ) { eHref = http://stackoverflow.com/questions/13731121/result.href; } else { eHref = $('base').attr('href') + 'index.php?route=product/product&product_id=' + result.product_id + '&keyword=' + keywords; } eLink.href = http://stackoverflow.com/questions/13731121/eHref; eDiv.appendChild( eLink ); eDiv.innerHTML = eDiv.innerHTML + result.desc; eListElem.appendChild( eImg ); eListElem.appendChild( eDiv ); eListElem.appendChild( document.createElement('br') ); eListElem.setAttribute( 'rel', eHref ); $(eListElem).bind('click', function(){ var gto = $(this).attr( 'rel' ); try { if( gto != false && gto.length > 0 ) { document.location = gto; } } catch( e ) {} }); eList.appendChild( eListElem ); } if( $('#livesearch_search_results').length > 0 ) { $('#livesearch_search_results').remove(); } $('#search_menu').append(eList); }}});\[/code\]The output is something like this (without \[code\]<ul>\[/code\]): \[code\] <li rel="http://url"> <span class="img_container"> <img src="http://url.jp"> </span> <div> <a href="http://url">MONS 1.0 (CTM 2013)</a> Description...</div> <br> </li>\[/code\]Is there any way to modify output to this:\[code\] <li rel="http://url"> <a href="http://url"> <---- <a> tag here <span class="img_container"> <img src="http://url.jp"> </span> <span class="product-container"> <------ <span> tag here <span class="title">MONS 1.0 (CTM 2013)</span> <------ <span> tag here, remove <a> tag <span class="description">Description...</span> <------ <span> tag here </div> </a> </li>\[/code\]This is beyond my JS knowledge.Thank you very much