Search all links and make a list

how can you find all the links (without bindings) and put them inside the list in the order in which they appear in jQuery.

For instance:

Lorem ipsum dolor sit amet, consectetur adipiscing elit, Donec sit amet ipsum ut justo fermentum hendrerit ultricies.

So this will be as follows:

Lorem ipsum

sit amet,

adipiscing elit.

sit amet ipsum ut justo fermentum hendrerit ultricies.

embed.ly , , , youtube/flickr , . , , , youtube (.. , ). (, , dolar, youtube , embed.ly).

php php.

:

<script type="text/javascript">

$(document).ready(function() {
  $("a").embedly({}, function(oembed, dict){
    if ( oembed == null)
      alert("no embedly content found");    
    var output = "<a class='embedly' href='#'><img src='"+oembed.thumbnail_url+"' /></a><span>"+oembed.title+"</span>";
    output += oembed['code'];
    $(dict["node"]).parent().html( output );
  });
  var anchors = $("a");  anchors.embedly();  anchors.filter("[href*=flx.me]").addClass("googlenl");
  $('a.embedly').live("click", function(e){
    e.preventDefault();
    $(this).parents('li').find('.embed').toggle();
  });
});
</script>

html , :

>    <div id="content">
>     <div class="youtube">
>             <p><a class="embedly" href="#"><img
> src="phpForum_files/hqdefault.jpg"></a><span>&#65333;&#65317;&#65318;&#65313;Chanpions
> League 2005-2006 RealMadrid vs Arsenal
> 2ndleg</span><div
> class="embed"><object height="360"
> width="640"><param name="wmode"
> value="opaque"><param name="movie"
> value="http://www.youtube.com/v/7aPGa9Gqj2c?fs=1"><param
> name="allowFullScreen"
> value="true"><param
> name="allowscriptaccess"
> value="always"><embed
> src="phpForum_files/7aPGa9Gqj2c.swf"
> type="application/x-shockwave-flash"
> allowscriptaccess="always"
> allowfullscreen="true" wmode="opaque"
> height="360"
> width="640"></object></div></p>
>     </div> </div>

. .

+3
4
$("#container").find("a").wrap("<li />").wrap("<ul />");

: http://jsfiddle.net/karim79/RmCGh/

+2

( "untested" ) - , -

$('a').not('[href^="#"]')

wrap <ul><li>...</li></ul>.

, , ( ), .

0
var links = document.anchors;

or

var links = element.getElementsByTagName('a');
0
source
 <p>
   Lorem ipsum <a href="http://www.link1.com" rel="nofollow">dolor</a> sit amet, <a href="http://www.link2.com" rel="nofollow">consectetur</a> adipiscing elit. <a href="http://www.link3.com" rel="nofollow">Donec</a> sit amet ipsum ut justo fermentum hendrerit ultricies.
  </p>
 <script type="text/javascript">
  $("p a").wrap("<ul><li></li></ul>");
 </script>
0
source

Source: https://habr.com/ru/post/1779076/


All Articles