Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove all href links using jquery

I am trying to remove all the links from a parsed site which has then had a div removed and placed in the main code. The problem is that I am trying to remove all the 'href' links in the extracted div but am unable to get anywhere. I have tried using 'CSS' and works but only in chrome and I have to use IE. I have looked at 'php simple html dom' parser to see if i could do it before the file is saved but can't get anything to work. so my last resort is to use 'jquery' but the problem is that the links to remove is being extracted from the file and is not directly in the code. If anyone could help me I would really appreciate it. below is the code I am using.

<head>
   <meta http-equiv="content-type" content="text/html;charset=UTF-8">
   <meta http-equiv="content-language" content="en">
   <meta name="viewport" content="width=500" />
   <title>example News</title>
   <link rel="stylesheet" type="text/css" href="site/wwwRand1.css">
   <?php 
      include( 'site/simple_html_dom.php'); 
      $html=file_get_html( 'http://example.com/home.php'); 
      $html->save('site/result.htm')                      
      ?>
   <script type="text/javascript" src="site/jquery.js"></script>
   <script type="text/javascript">
      $('document').ready(function() {
      $('#postsArea').load('site/result.htm #postsArea');
      });
   </script>
</head>
<body>
   <div id="wrap">
      <div id="postsArea"></div>
   </div>
</body>
like image 385
Aston Avatar asked Dec 25 '22 16:12

Aston


2 Answers

Just remove the href attribute from the <a /> tags

$("#postsArea").load( "site/result.htm", function() {
   $("#postsArea a").removeAttr("href")
});

If you still want the tags to appear clickable...

$("#postsArea a").removeAttr("href").css("cursor","pointer");

Hope this helps

like image 155
heymega Avatar answered Dec 28 '22 05:12

heymega


Try this:

$('document').ready(function () {
    $.ajax({
         url : 'site/result.htm',
         dataType: 'html',
         success : function(html){
              $html = $(html).find(a).attr("href", "");
              $("#postsArea").html($html);
         },
         error : function(){
              $("#postArea").html("<div>No Data Found.</div>");
         }
    })
});
like image 43
Frogmouth Avatar answered Dec 28 '22 07:12

Frogmouth