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

  • Home
  • SEARCH
  • 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 8268963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:04:07+00:00 2026-06-08T06:04:07+00:00

Example code var jqxhr=$.getJSON(http://search.twitter.com/search.json?callback=?,{q:query}, function(data) { … question. }); Question Now i need to

  • 0

Example code

var jqxhr=$.getJSON("http://search.twitter.com/search.json?callback=?",{q:query},
                function(data) {
                    ... question.               
                });

Question

Now i need to create for each tweet result something like this (for example…)

<article class="tweet">
    <header>
        <img class ="tweet_img"src="data.profile_image_url"/> 
    </header>
    <p class="tweet-text">data.text</p> 
</article>

Well, i know several ways to append each result to the document:

  1. Creating a big HTML string and add the data from JSONP and append this to some container.
  2. Create a p element, a header element… work with them and after that append a final Element to some container.

Now the question is: with your experience what is the correct way to do this?
I mean the correct way using good principles.

Please dont ask about the html, it’s dumb example.
Thanks.

  • 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-08T06:04:08+00:00Added an answer on June 8, 2026 at 6:04 am

    There are several valid approaches that each have their own advantages…

    The technique of just generating the HTML as a string in your java code and adding it with .innerHTML is known to be one of the fastest performing approaches…but it provides very little validation of your HTML.

    Alternatively, you can build the HTML using DOM methods directly, creating tags and appending them to build the structure. This is generally safer in that you have more validation going on, but the DOM methods are extremely wordy, which makes them a bit painful to type…and the code is even more verbose as you have to add attributes one at a time as well.

    My personal preference, especially since you’re already using JQuery, would be to build the tags and text nodes using JQuery, and put them together using JQuery, which allows you to do so in bite-sized, more human-verifiable units, without becoming overly verbose.

    This also has the advantage that JQuery’s methods of producing new tags give you additional support for older browsers that did not adhere to DOM standards. Hopefully you don’t actually have to care whether your page works for those older browsers, but more compatibility never hurts either.

    In that approach, you’d write something like the following:

    var article = $('<article class="tweet"></article>');
    var header = $('<header></header>');
    var image = $('<img class="tweet_img" src="' + data.profile_image_url + '"></img>');
    var tweet = $('<p class="tweet-text">' + data.text + '</p>');
    
    header.append(image);
    article.append(header, tweet);
    $("#id_of_content_area_to_add_the_tweet_to").append(article);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I saw in jQuery the code : var jqxhr = $.ajax( example.php ) .done(function()
Code example: <script> var data = new Array(); data[0] = 'hi'; data[1] = 'bye';
The following code sample (also at http://jsfiddle.net/MZwBS/ ) var items = []; items.push({ example:
Ok, in my code I have for example, this: $('.follow').click(function(){ var myself = $(this);
Example code: var connection = null; function onConnect(status) { im_a_big_error.log('wtf'); // Why it doesn't
I have the following example code var object = { userDefinedFunction : function(){ //no
I am having trouble with the json.getJSON method. Here is my current code: var
I have this example code: var foo = { self: this, init: function(){ self.doStuff();
I have this simple example code: var request = mozIndexedDB.open('MyTestDatabase'); request.onsuccess = function(event){ var
This is an example code from the prototype site. var url = '/proxy?url=' +

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.