Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

finidng length of XML for JQuery / javascript variable

Featured Replies

Hi,

 

I've found some great templates and jQuery scripts.

 

One invovles having a UL with individual LI picture elements inside.

 

<div id="slider">

<ul>

<li><a href="http://webaddress"><img'>http://webaddress"><img'>http://webaddress"><img'>http://webaddress"><img'>http://webaddress"><img src="images/02.jpg" alt="" /></a></li>

<li><a href="http://webaddress"><img src="images/03.jpg" alt="" /></a></li>

<li><a href="http://webaddress"><img src="images/04.jpg" alt="" /></a></li>

<li><a href="http://webaddress"><img src="images/05.jpg" alt="" /></a></li>

</ul>

</div>

 

When you click on the slider div, this function starts to run:

 

 

 

this.each(function() {

var obj = $(this);

var s = $("li", obj).length;

var w = $("li", obj).width();

var h = $("li", obj).height();

 

 

.... this basically gets the number of LI elements in #slider, their width and height and along with the rest of the code enables you to slide back an forth the content of slider, so you only see one picture element at a time.

 

However, I am updating the LI elements on the fly, appending LI to the UL from an XML list of image sources.

 

 

$(document).ready(function(){

 

$.ajax({

type: "GET",

url: "sites.xml",

dataType: "xml",

success: function(xml) {

$(xml).find('site').each(function(){

var id = $(this).attr('id');

 

$('#k').append('<li><a href="http://webaddress"><img src="images/'+id'.jpg" alt="" /></a></li>');

 

});

}

});

});

 

 

Now I want to feed the number of total child elements in the XML to the previous function, so its knows how many LI elements there are. Any ideas how I would go about that?

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.