Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting only a href tags within a div and disable them

Tags:

html

jquery

I am trying to figure out how to disable links within a specific div. What I currently have is this...

    function Lock() {
    var obj = document.getElementById("tempplateInfo");
    obj.disabled = 'true';
    $(function () {
        //grab all a tags
        $('a').each(function () {
            //click on a link....
            $(this).click(function () {
                alert($(this).attr('href') + ' is not available');
                //disable link
                return false;
            });
        });
    });
}

This currently select all the link on the page. I don't want all the links, just the few that are inside of a div?

Anyway to get that done... I thought about 'divId a'. But that didn't work at all, all the links were suddenly available. I am doing this using jquery btw.

like image 406
SoftwareSavant Avatar asked Dec 30 '25 13:12

SoftwareSavant


1 Answers

You need to learn jQuery selectors.

You want #someId a.

like image 100
SLaks Avatar answered Jan 02 '26 03:01

SLaks