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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Traversing through HTML data?

  • 15-08-2012 1:37pm
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 2,040 ✭✭✭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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 27,370 ✭✭✭✭GreeBo


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


  • Advertisement
  • Registered Users, Registered Users 2 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