Solved

Pulling data from a list

Posted on 2013-11-11
1
174 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now