0

Method

   function CreateButton(tag, isVisible, text, event) {
        var elem;
        elem = $(document.createElement('input'));
        elem.type = tag;
        elem.prop('value', text);
        elem.css('display', isVisible == 'true' ? '' : 'none');
        elem.click(event);
        return elem;
    }

caller

 function DrawButtons(mode) {
        var text = mode == 'true' ? 'Cancel' : 'Close';
        $('#fdEitDetail').append(CreateButton('button', mode, 'Save & Close', save));
        $('#fdEitDetail').append(CreateButton('button', mode, 'Save & mark Completed', mark));
        $('#fdEitDetail').append(CreateButton('button', mode, text, close));
}

The method is supposed to be creating button , but it is creating text box.

One of the other methods say

function CheckBox(tagName, isEditable)
{
 elem = $(document.createElement('input'));
            elem.type = tagName;
            elem.attr('checked', text ? 'checked' : '');
}

caller

$('#dvCheck').append(CheckBox('checkbox', mode));

it is creating text box. Any help??

ankur
  • 4,565
  • 14
  • 64
  • 100
  • Check this fiddle http://jsfiddle.net/8S7st/ – tilda Jan 22 '14 at 10:14
  • @tilda it is working but is pure old school javascript, i was following this link for performance too http://stackoverflow.com/questions/268490/jquery-document-createelement-equivalent/268520#268520 can't we do some thing with jquery rather than doing the fiddle way though it is working perfectly – ankur Jan 22 '14 at 10:17
  • You posted your code in js so I thought that's what you want. Try to transform it to jquery, put it in fiddle and please post it here to see where's the problem. – tilda Jan 22 '14 at 10:21
  • @tilda there is no problem in code like error , it is just that inplace of checkbox and button only input type text is being created by my code – ankur Jan 22 '14 at 10:24

1 Answers1

0

I see that you want to create jQuery Object ( $(document.....)) ? $(document.createElement('input')) ==> Make jQuery Object . To create jQuery Object you can use simply $("") Example:

$(“<div>”).attr(“id”,”div-source”)
.addClass(‘highlight’)
.css(“color”,”blue”)
.on(“click”,function(){}
);

In your case , you can use

$("<input>").attr("type",tagName).attr('checked', text ? 'checked' : '');

Hopt it helps you

LogPi
  • 706
  • 6
  • 11
  • after using the above code it has created the checkbox but it is coming checked always though the value of text is false. – ankur Jan 22 '14 at 10:06
  • function CheckBox(tagName, text) { var elem = $("").attr("type",tagName).attr('checked', text ? 'checked' : ''); return elem; }; you can use like this and call CheckBox('datetime','checked'); – LogPi Jan 22 '14 at 11:03