Solved

Pulling data from a list

Posted on 2013-11-11
1
188 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
[X]
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
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

I have answered several questions lately that were solved utilizing the power of jQuery's AJAX functions, so I thought I would write an article demonstrating the ease of use. Why should I use jQuery as opposed to regular JavaScript? Now I know…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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…

732 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