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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:36:54+00:00 2026-06-13T01:36:54+00:00

Inside my jquery Append() I wan’t to run an IF-statement to include an image

  • 0

Inside my jquery Append() I wan’t to run an IF-statement to include an image on all my objects except on the first one.

Like:

var i = 0;

$('#divDetailsForSelectedInfo').append(
    '<div class="roundedAndBoxShade leftResultObject" id = "' + value.Query.Id + '">'+
    '<div class="leftResultObject_inner">' +
if (i > 0){
   <img src="/img.jpg"/>;
}
'<div>asdf</div>');

The code is generated by Json+Jquery and then it is all appended on a div in my index-file.
As far as I’ve been able to tell through immence google-ing this can’t be done, but I might be wrong?

If it is indeed “impossible”, could the :first selector in Jquery be used in some cool way?

  • 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-13T01:36:55+00:00Added an answer on June 13, 2026 at 1:36 am

    A simpler solution:

    var i = 0;
    $('#somediv').append(
        'html before' + 
        (i > 0 ? '<img src="/img.jpg"/>': '') +
        'more html'
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know if I can include some Jquery inside another JQuery
How can I insert jquery inside an html tag like using it in onclick
I would like an alternative to using callback method inside of jQuery's .val() method
I am trying to upload an image from inside a JQuery modal. The form
I'm trying to write a bit of jquery which finds all h2 tags inside
I'm aware of jQuery's append() which appends html inside the selected element. I want
The function I called inside jquery returns undefined. I checked the function and it
It seems that i cannot access $(this) inside jquery ajax success function. please see
I have a jqGrid loaded by AJAX inside a jQuery UI Dialog. Everything is
I'm trying to override a method inside a jquery widget. The method can be

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.