Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Pulling data from a list

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

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
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…
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…

839 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