0

I am trying to disable all elements of Div tag. I get success on input types. But not able to disable links. I have also tried this, but it is not working. Here is the code I have tried(But it works for input only):

 $('#EditorRows *').attr('disabled', true);

I know disable for input types but I want to achieve that type of mechanism for links.

1st PartialView Code:

<div id="Part2">
<div id="EditorRows">
<%= Html.ActionLink("Add another...", "Add", null, new { id = "addItem" }) %>
<%Html.RenderPartial("_InsertServices", Model);%>
</div>
<div id="DontAppend">
<input type="button" id="btnEdit" value="Edit" hidden="hidden"/>
<input type="button" id="btnDone" value="Done" />
</div>
</div>

2nd PartialView

<div class="EditorRow">
<% using (Html.BeginCollectionItem("services"))
{ %>
<table id="table1">
<tr><td>
NOS:</td><td>
<%:Html.DropDownListFor(model=>model.Id,(SelectList)ViewData["crmServiceType"] as SelectList,"---")%>
</td>
<td>
Comment:</td><td>
<%=Html.TextBoxFor(model => model.Comment, new { size = "20" })%></td>
<td>
<a href="#" class="deleteRow">delete</a>
</td>
</tr>
</table>
<% } %>
</div>

script:

    $("#addItem").click(function () {
            $.ajax({
                url: this.href,
                cache: false,
                success: function (html) { $("#EditorRows").append(html); }
            });
            return false;
        });

        $("a.deleteRow").live("click", function () {
            $(this).parents("div.EditorRow:first").remove();
            return false;
        });

$('#btnDone').click(function () {
      $('#EditorRows *').attr('disabled', true);
    }
    $('#btnEdit').click(function () {
      $('#EditorRows *').attr('disabled', false);
    }
Community
  • 1
  • 1
Dhwani
  • 7,484
  • 17
  • 78
  • 139

6 Answers6

3

To disable links use this

$('div a').unbind('click');

Ore in your case:

$('#btnDone').click(function () {
    var $rows = $('#EditorRows');
    $rows.find('input, select, textarea').attr('disabled', true);
    $rows.find('a').unbind('click');
}
Tommy Bjerregaard
  • 1,089
  • 11
  • 24
2

try this

$('#EditorRows').find('a').each(function(){
   $(this).replaceWith($(this).text());
});

Update

To disable :

$('#EditorRows').find('a').bind('click', false);

To enable :

$('#EditorRows').find('a').unbind('click', false);
IT ppl
  • 2,626
  • 1
  • 39
  • 56
0
$('div').find(':input').prop('disabled',true);//this line will this able all inputs including buttons.
$('div').find('a').each(function(){
   $(this).removeAttr('href');
   $(this).unbind('click');
});//this will take care of the links

I think this will take care of the problem

misoukrane
  • 304
  • 2
  • 3
0

use off method of jquery.

$('#Yourdiv a').off('click');

$('#yourDiv').find('input').attr('disabled',true);

or else simple is just return false when anchor clicked.

$('#Yourdiv a').on('click',function(e)
                  {
                   return false;  // or e.preventDefault();
                  });
Ravi Gadag
  • 15,735
  • 5
  • 57
  • 83
0

It works for input only because they have disable attribute. To disable link try

if you want just to delete the link redirect.

$("#youdivname").find('a').removeAttr('href') 

This will active it again :

$("#yourdivname").find('a').attr('href','link')

where link is the redirect.

steo
  • 4,586
  • 2
  • 33
  • 64
0

The first solution that came to mind, but it does not pretend to be elegant http://jsbin.com/icijox/4/edit

Dmytro Filipenko
  • 861
  • 1
  • 9
  • 25