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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:59:28+00:00 2026-06-12T23:59:28+00:00

I have the following code which takes an input from an xml and creates

  • 0

I have the following code which takes an input from an xml and creates an unordered list.

$(function() {
            var map = function() {
                    if ($(this).is("parent")) {
                        var children = $(this).children().map(map).get().join('');
                        $(this).children().remove();
                        var result = "<li class='BGOfDiv'>" + $(this).text();
                        return result + "<ul>" + children + "</ul></li>";
                    }
                    if ($(this).is("Children")) {
                        return "<li class='BGOfDiv'>" + $(this).text() + "</li>";
                    }
                };

                $.get("test.xml", function(data) {
                    var result = $(data).map(map);
                    $("#org").html(result[0]);
                    $("#org").jOrgChart({
                            chartElement : '#chart',
                            dragAndDrop  : false
                        });
                        dragNodes();
                }, "html");

            }); 

Currently,my xml looks like this

<?xml version="1.0" encoding="utf-8"?>
<Parent>Director
    <Children>Exe Director1</Children>
    <Children>Exe Director2</Children>
    <Parent>Exe Director3
        <Children>Sub Director 1</Children>
        <Children>Sub Director 2</Children>
        <Parent>Sub Director 3
            <Children>Cameraman 1</Children>
            <Children>Cameraman 2</Children>
        </Parent>
    </Parent>    
</Parent>

However,the xml will be made to hold the paths of certain images which I need to apply as the background-image for each node.That is my xml will look like

<?xml version="1.0" encoding="utf-8"?>
<Parent>../images/1.jpg
    <Children>../images/2.jpg</Children>
    <Children>../images/3.jpg</Children>
    <Parent>../images/4.jpg
        <Children>../images/5.jpg</Children>
        <Children>../images/6.jpg</Children>
        <Parent>../images/7.jpg
            <Children>../images/8.jpg</Children>
            <Children>../images/9.jpg</Children>
        </Parent>
    </Parent>    
</Parent>

I understand that I will need to use the .css property of jquery and set the background-image when I create the new <li> element but I am not able to figure out how that can be done.

Thanks for looking.Any help will be appreciated.

  • 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-12T23:59:29+00:00Added an answer on June 12, 2026 at 11:59 pm

    If $(this).text() returns the url of the file, you could simply add the style in the <li> element

    "<li class='class' style='background-image: url(" + $(this).text() + ");'>...</li>"
    

    Of course you would probably need to setup other CSS like background-position, background-repeat, etc. Or use the short version of the css like

    "<li class='class' style='background: url(" + $(this).text() + ") no-repeat 0 0;'>...</li>"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which takes List of boolean as a parameter then
i have the following code which switches some fullscreen-background-images (fadeOut, fadeIn). setInterval(function() { var
I have the following code which takes a touch on one button and draws
I have the following code: <div><strong>Name: </strong><?php echo anchor('http://'.$link, $row->Name); ?></div> Which takes a
I have the following code which is working, I was wondering if this can
I have a function named OpenAccount() which takes in the details from the User
I have following code which works for radio buttons but need to be changed
I want to know is below code correct ? I have following code which
I have the following code which definitely returns a proper data result if I
I have the following code which is used to upload large files (~6MB) to

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.