0

The company I am working for handed me over a messy website ran using templates, so some elements in the website are automatically generated and are active links.

My main problem is that there are some elements on the site are active links that aren't suppose to be links at all. I was wondering if there is a way to remove the link from an html element using JQuery and maybe CSS?

this will help me tremendously, thanks in advance. I need to remove all href's from class 'slider'.

Here is some of my jquery, can someone please show me how to add it?

<script type="text/javascript">
    $(document).ready(function(){
        $("#productsLink").hover(function(){
            $("#productsMenu").slideDown();
        });
        $("#productsLink, #productsMenu").hover(function(){
            $("#productsLink").css("color","red");
        });
        $(".spacer", this).hover(function(){
            $("#productsLink").css('color', 'white');
            $("#productsMenu").slideUp();
            $("#aboutLink").css('color', 'white');
            $("#aboutMenu").slideUp();
        });
    });
    </script>
7
  • can you show some code/sample HTML? before anyone gets downvoted due to assumption Commented Mar 31, 2012 at 22:47
  • This is a perfect example of what I am dealing with... (need to remove the link) <a href="http"//www.foobar.com"><div>HELLO</div></a> Commented Mar 31, 2012 at 23:00
  • is this HTML in an isolated container? or is it all over the page? do they all come in the same url? Commented Mar 31, 2012 at 23:07
  • Yes isolated containers, all over the page, all with the same url... Commented Mar 31, 2012 at 23:10
  • can you post all of the related HTML, preferrably at least 2 of these containers. we can't pinpoint how to pick out these links apart from the normal links you want retained unless we see some structure. Commented Mar 31, 2012 at 23:12

4 Answers 4

1

try unwrapping the sliders using .unwrap(), assuming all these links have the class slider and they are directly wrapped in an anchor tag.

$('.slider').unwrap()
Sign up to request clarification or add additional context in comments.

Comments

1

If you want to remove links with the class name slider from the DOM:

$('a.slider').remove();

2 Comments

Do you have any way of differentiating the links you want deleted from the ones you want kept? You can't just delete all :active links because it'll remove your authorized ones when you click on them. Do the old ones have a particular class name or ID or title? Or they located in common elements?
The old one has a class name of 'slider' I would like to disable all links associated with class name 'slider'.
1

You can remove all href attributes from links with class slider with this code:

$('a.slider').removeAttr('href')

This will keep the content of the elements intact and just disables them as a link.

Comments

0

CSS is no help here, it could only be used to hide elements completely.

You can use the replaceWith method to turn specific a elements into span elements. Example:

$('a.something, a.someother').replaceWith(function(){
  return $('<span/>').text($(this).text());
});

1 Comment

Depending on the case .unwrap('a') might also be useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.