Solved

Pulling data from a list

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

930 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

9 Experts available now in Live!

Get 1:1 Help Now