0

I am sending the div content after modifications on page as a preview of that page in dialog box using clone in jquery.Now i want to make the cloned div which is previewed in dialog as readonly.How can i do that? help me

function callPreview()
{
$('#maincontainer').clone().appendTo('#previewDiv');

document.getElementById('previewDiv').disabled=true;
$.fx.speeds._default = 500;
$(function() {

        $( "#previewDiv" ).dialog({
            autoOpen: false,
            width:600,
            height:800,
            autoClose: false,
            show: "fold",
            hide: "core",
            resizable:false

        });

        $( "#previewBtn").click(function() {
            $( "#previewDiv" ).dialog( "open" );
            return false;
        });
});
}
Vivek
  • 10,978
  • 14
  • 48
  • 66
Vinay Gayakwad
  • 526
  • 4
  • 10
  • 20

2 Answers2

4

If readonly means that no input from user allowed,but still, the user can select and copy text, you can try to specify the 'readonly' attribute for each 'input' element in the div:

$("input","#previewDiv").attr('readonly', true);
Alex Pacurar
  • 5,801
  • 4
  • 26
  • 33
  • This will make ALL inputs on the page readonly, and not only the ones within the div. try `$("#previewDiv input")` instead. – tobias86 Mar 28 '11 at 07:02
  • @tobias86: for some reason, the jquery website is down (at least for me), but see http://stackoverflow.com/questions/306583/this-selector-and-children ... so the second argument is representing a context in which the first selector is searched... so this will return references of the input element within the div – Alex Pacurar Mar 28 '11 at 07:28
  • interesting...I've never seen this. I based my comments on some fiddling I did. When I had a div containing 3 dummy inputs, the selector `$("#div input")` returned an array of length 3, but when I tried `$("input, #div")` the array length was 4. I just jumped to a conclusion that the latter was selecting more than only the elements within the div. Oh well, I learned something today :). Thanks! – tobias86 Mar 28 '11 at 07:37
0

$("#selector :input").attr("disabled", true);

This works for me!

Jasmeen
  • 876
  • 9
  • 16