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 8126615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:12:48+00:00 2026-06-06T07:12:48+00:00

I have a search page like <div class=> <input id=search-input type=text class=input-medium search-query span4>

  • 0

I have a search page like

<div class="">
    <input id="search-input" type="text" class="input-medium search-query span4">
</div>

<div id="result">

</div>

<div id="result-template">
    <div class="hide-item item" id="item">
        <div style="float:left">
            <img class="thumbnail" src="" alt="" />
        </div>
        <div id="name">
            <p class="title"></p>
            <p class="views"></p>
        </div>
    </div>
</div>  

and jQuery as

$(function(){
    $('#search-input').live('keyup',function() {
        var search_input = $(this).val();
        var keyword = encodeURIComponent(search_input);
        var yt_url = 'http://gdata.youtube.com/feeds/api/videos?q='+keyword+'&format=5&max-results=10&v=2&alt=jsonc';

        $.ajax({
          url: yt_url,
          type: 'GET',
          dataType: 'jsonp',
          complete: function(xhr, textStatus) {
            //called when complete
          },
          success: function(response, textStatus, xhr) {
            if(response.data.items) {
                var template = $('#item').clone();
                $('#result').html(template);
                $.each(response.data.items, function(i, data) {
                    console.log(data)
                    search_data = {
                        'id': data.id,
                        'title': data.title,
                        'views': data.viewCount,
                        'thumbnail': data.thumbnail['sqDefault'],
                    }
                    video_result_template(search_data);
                });
            } else {
                // var template = $('#item').clone();
                // $('#result').html(template);
            }
          },
          error: function(xhr, textStatus, errorThrown) {
            //called when there is an error
          }
        });
    });
});

// filling out the search template
function video_result_template(data) {
    var item = $('#item').clone();
    item.removeClass('hide-item');
    item.find('img').attr('src', data.thumbnail);
    item.find('.title').html(data.title);
    item.find('.views').html(data.views);
    $('#item').attr('id', data.id);
    item.addClass('view-item');
    // $('#result').append(item).fadeIn(); // slow/fast?
    $('#result').append(item).fadeIn('slow');
}

I get the results on the div with title, views, url. Now when I click div, the following jQuery is fired

$(function(){
    $('.item').live('click', function(){
        // alert(this.id);
        console.log($(this));
        var url = $('#video-frame').attr('src');
        var new_url = url.replace(/embed\/[\w -]*/g, 'embed/' + this.id);
        alert($('.title').html() + ',' + new_url);
        $('#video-frame').attr('src', new_url);
    });
});

which alerts right title but the url(or video_id is of the next video in the list).

When I see my html from firefox I see the following

 <div id="result" style="display: block;">
    <div id="lqT_dPApj9U" class="item view-item">
      <div style="float: left;"><img alt="" src=
      "http://i.ytimg.com/vi/S2nBBMbjS8w/default.jpg" class="thumbnail" /></div>

      <div id="name">
        <p class="title">Coke 2012 Commercial: "Catch" starring NE_Bear</p>

        <p class="views">619167</p>
      </div>
    </div>

    <div id="hKoB0MHVBvM" class="item view-item">
      <div style="float: left;"><img alt="" src=
      "http://i.ytimg.com/vi/lqT_dPApj9U/default.jpg" class="thumbnail" /></div>

      <div id="name">
        <p class="title">Coca-Cola Happiness Machine</p>

        <p class="views">4791156</p>
      </div>
    </div>

    <div id="item" class="item view-item">
      <div style="float: left;"><img alt="" src=
      "http://i.ytimg.com/vi/S2nBBMbjS8w/default.jpg" class="thumbnail" /></div>

      <div id="name">
        <p class="title">Coke 2012 Commercial: "Catch" starring NE_Bear</p>

        <p class="views">619167</p>
      </div>
    </div>
  </div>
  • If seen clearly the first and last div has same data elements
  • infact the difference is that the last div is copy of first element
  • The last element has invalid id=”item”(must be video id)

Question
How can I fix this issue?

JSFiddle
http://jsfiddle.net/hhimanshu/F5NHK/

Required
After search, click on any video div and it must give right video id and title
P.S. in fiddle clicking on list is not doing anything(don’t know why, it works on my system though)

  • 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-06T07:12:49+00:00Added an answer on June 6, 2026 at 7:12 am

    In function

    // filling out the search template
    function video_result_template(data) {
        var item = $('#item').clone();
        item.removeClass('hide-item');
        item.find('img').attr('src', data.thumbnail);
        item.find('.title').html(data.title);
        item.find('.views').html(data.views);
        $('#item').attr('id', data.id);
        item.addClass('view-item');
        // $('#result').append(item).fadeIn(); // slow/fast?
        $('#result').append(item).fadeIn('slow');
    }  
    

    replace $('#item').attr('id', data.id); to item.attr('id', data.id);

    Thank you @arhen for providing this solution

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

Sidebar

Related Questions

a have a page that consist of: <input type=radio id=oqcline class=section/>OQC Line <input type=radio
I have a search page where I would like to stop the user entering
I have a page that displays search results and has a DOM like the
If I have a structure like: <div id=listofstuff> <div class=anitem> <span class=itemname>Item1</span> <span class=itemdescruption>AboutItem1</span>
I have a search result page that I'm trying to layout but I'm having
I have a search page which uses a simple ajax request to get new
i have a search page in my site, where user can search all the
I have a search page that if there is results in the list it
I have a search page with the following scenarios listed below. I was told
I have a search page on my MVC site that contains a list of

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.