Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8958825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:18:16+00:00 2026-06-15T15:18:16+00:00

I downloaded a livesearch JavaScript plugin for my site, it’s working, but I need

  • 0

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:

    $.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[i].img != null ) {
                var eImg = document.createElement( 'span' );
                eImg.className = "img_container";
                var img = new Image();
                img.src = result[i].img;
                eImg.appendChild( img );
            }
            else {
                eImg = document.createElement( 'span' );
                eImg.innerHTML = ' ';
            }
            eDiv = document.createElement( 'div' );
            eLink.appendChild( document.createTextNode(result[i].name) );
            if( typeof(result[i].href) != 'undefined' ) {
                eHref = result[i].href;
            }
            else {
                eHref = $('base').attr('href') + 'index.php?route=product/product&product_id=' + result[i].product_id + '&keyword=' + keywords;
            }
            eLink.href = eHref;
            eDiv.appendChild( eLink );
            eDiv.innerHTML = eDiv.innerHTML + result[i].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);
    }
}});

The output is something like this (without <ul>):

  <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>

Is there any way to modify output to this:

  <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>

This is beyond my JS knowledge.

Thank you very much

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:18:17+00:00Added an answer on June 15, 2026 at 3:18 pm

    On the severe disclaimer that this is untested, I’d say yes!

    The code is neatly divided up, makes it easy to read, let’s keep in that spirit.

    Towards the top we see the following:

    var eList = document.createElement( 'ul' );
    eList.id = 'livesearch_search_results';
    var eListElem;
    var eLink;
    var eHref;
    

    These variables are declared but not defined. They will be used over and over again to build each <li>. We’re moving the link (eLink) so we can leave that, but we’re also changing a <div> to a <span>, as well as adding several other elements; namely product container, title, and description. Let’s pop in some variables for those, while we’re here (the original author appears to have not defined eDiv up here, we’ll be replacing that with ePCont, anyway):

    var eList = document.createElement( 'ul' );
    eList.id = 'livesearch_search_results';
    var eListElem;
    var eLink;
    var eHref;
    var ePCont, eTitle, eDesc;
    

    The next step is two-fold.

    First we see a bunch of document.createElements (some in if-statements, some not). document.createElement makes a new DOM element of the specified type. It does not add the element to the document, it only builds an instance of it, so it doesn’t matter what order they’re created in. This brings us to part two: [element].appendChild([element]) places one element in the tree under another. If an element in that tree belongs to the document, it will be displayed. This means first we’ll create a series of objects, then add them to each other, and finally add the topmost element to the document.

    We’re going to drastically rewrite large parts of this code, but the first part (up through where the images are created) is just fine:

            eListElem = document.createElement( 'li' );
            eLink = document.createElement( 'a' );
            if( result[i].img != null ) {
                var eImg = document.createElement( 'span' );
                eImg.className = "img_container";
                var img = new Image();
                img.src = result[i].img;
                eImg.appendChild( img );
            }
            else {
                eImg = document.createElement( 'span' );
                eImg.innerHTML = '&nbsp;';
            }
    

    The next line defines the container div that we now call ePCont, let’s rewrite it appropriately (and give it a class):

    ePCont = document.createElement( 'span' );
    ePCont.className = "product-container";
    

    The line after THAT puts some text in the link. We’re putting an element in it instead, so we can safely remove it, but the if statement after that (which makes sure we’re going to be using a kosher url) stays:

            if( typeof(result[i].href) != 'undefined' ) {
                eHref = result[i].href;
            }
            else {
                eHref = $('base').attr('href') + 'index.php?route=product/product&product_id=' + result[i].product_id + '&keyword=' + keywords;
            }
            eLink.href = eHref;
    

    Finally, let’s create our two new spans:

    eTitle = document.createElement( 'span' );
    eDesc = document.createElement( 'span' );
    

    and populate them:

    eTitle.appendChild( document.createTextNode(result[i].name) );
    eDesc.appendChild( document.createTextNode(result[i].desc) );
    

    and set their classes:

    ePCont.className = "title";
    ePCont.className = "description";
    

    Now it’s time to append everything to everything else. We’ll start from the lowest elements, and work our way upwards.

    ePCont.appendChild(eTitle);
    ePCont.appendChild(eDesc);
    eLink.appendChild(eImg);
    eLink.appendChild(ePCont);
    eListElem.appendChild(eLink);
    

    The rest of the document should flow more or less as it did:

        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 );
    
        ...
    

    Again, totally untested, but I hope my description will give you enough knowledge of the workings of this plug-in to trouble shoot it!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I downloaded a livesearch javascript plugin for my site, it's working, but I need
I downloaded the latest source of mod_wsgi from https://code.google.com/p/modwsgi/source/checkout , but I can’t compile
I downloaded example code of an Android project featuring AdMob ads from here .
I downloaded the avalon wizard but I can't find anywhere any sample code. Does
Downloaded and place phundament3 in local machine, ya its working but not when trying
I downloaded and edited a code that from internet, basically what I want to
I downloaded the kernel source for htc explorer (pico-gb-crc-2.6.38-71ff0f2). But I cannot find the
I downloaded around 1000 images from URLs to the iPhone file system, but I'd
Recently downloaded some code for a minor open-source project related to a small webgame
I downloaded GCC 4.5 from http://www.netgull.com/gcc/releases/gcc-4.5.0/ but when I try to setup / build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.