Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Traversing through HTML data?

Options
  • 15-08-2012 2:37pm
    #1
    Registered Users Posts: 543 ✭✭✭


    Specifically <div> tags, but there are some classes there too. It's a mess. Ideally I'd convert it to an XML and be able to access the elements via the div name or something. I'm not entirely sure what way to go about it.

    Effectively I've an AJAX call that returns HTML data (don't ask why) and I want to extract the elements from the code.


Comments

  • Registered Users Posts: 2,022 ✭✭✭Colonel Panic


    What have you tried? I'm assuming Javascript here since you mention getting the HTML via an AJAX call. You can traverse that data with Javascript.


  • Registered Users Posts: 3,805 ✭✭✭Setun


    Why not use jquery if you're looking for a quick solution? Should be handy enough with selectors, unless the html is really all over the place.


  • Registered Users Posts: 46 Paddy GT


    I would agree ... JQuery is best for this - as long as your divs have id or class attributes traversing should be pretty easy


  • Registered Users Posts: 543 ✭✭✭solarith


    I was using jQuery for some, but others do not have id's or names! Mad, eh?

    Can I use jQuery to find, for example, the first instance of a <p>, the second instance of a <p>, etc..?


  • Registered Users Posts: 27,161 ✭✭✭✭GreeBo


    switch the call to a server side call and process it there, then return that from your Ajax call.


  • Advertisement
  • Registered Users Posts: 543 ✭✭✭solarith


    GreeBo wrote: »
    switch the call to a server side call and process it there, then return that from your Ajax call.
    I don't have access to the server ;D

    OK - here is the code to process the 1st element without a name, for anyone who needs:

    var variable = $("a:eq(0)").html();


    So this will get the text in the 1st <a .....> </a>, increase 0 for others.


Advertisement