Solved

Pulling data from a list

Posted on 2013-11-11
1
178 Views
Last Modified: 2013-11-12
I'm trying to pull the data from a list, so I can rewrite it to something else.

So what I've done so far is get the text from the li, however I cant figure out how to get the href out, ideally I would like to pull the target out as well, however not sure if I can use target the way Im trying to.

So my html code is:-
  <ul id="newTabs" class="tabs">
    <li><a href="test2.php" target="test">Tab 1</a></li>
    <li><a href="test2.php" target="test">>Tab 1</a></li>
    <li><a href="test2.php" target="test">>Tab 1</a></li>
    <li><a href="test2.php" target="test">>Tab 1</a></li>
  </ul>

Open in new window


What Ive got soo far is:-
  <script>
    $(document).ready(function (){
        $('#newTabs li').each(function(){
            console.log("Text of link is - " + this.textContent);

            //Below this line doesnt work
            console.log("HREF is - " + this.parent.attr('href'));
            console.log("HREF is - " + this.parent.attr('target'));
        });
    });
  </script>

Open in new window


Anyone got any advise on how to pull the required data?
0
Comment
Question by:tonelm54
1 Comment
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 39640159
Hi,

this should work (I used a div for output):
$(document).ready(function (){
        $("#newTabs li").each(function(){
            $("#ResultDiv").append("<p>Text of link is - " + $(this).text() + "</p>");

            //Below this line doesnt work
            $("#ResultDiv").append("<p>HREF is - " + $("a",this).attr("href") + "</p>");
            $("#ResultDiv").append("<p>Target is - " + $("a",this).attr("target") + "</p>");
        });
    });

Open in new window


See here: http://jsfiddle.net/EE_RainerJ/8yARJ/

HTH
Rainer
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question