Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi...

I am facing a problem in jquery function. I have created dynamic div in jqguery function & I get dynamic div id from it...now i wanna hide this div by div id in another jquery function onbutton click event..but when i hide a particular div,every div is being closed...

please help me out of this...


XML
<script type="text/javascript">

        function myFunction() {

            debugger;

               var v = document.getElementById('<%=hdnvalue.ClientID%>').value;

            $('#div11').append("<div id='" + v + "' style='direction:ltr;display: inline-block; direction: ltr; text-align: left'><table style='width:100px;height:150px;border-style: groove'><tr><td style='background-color:aliceblue'><input type='image' src='Images/close-16.png' id='" + v + "'  önClick='myDivFunction(this.id)' align='right'></td></tr><tr><td style='height:50px'><label for='message'>Message Show</label></td></tr><tr><td><textarea rows='5' cols='20' name='message' placeholder='type your message'></textarea></td></tr><tr><td><button type='button' name='button' value='button'>Send</button></td></tr></table><div><div></div>");

                var y = parseInt(v) + 1;
              document.getElementById('<%=hdnvalue.ClientID%>').value =  y;

        }


        function myDivFunction(obj) {
            debugger;
            alert(obj);
            var x = document.getElementById(obj);

            $(x).hide();

            return false;
        }

    </script>
Posted
Updated 2-Dec-13 21:16pm
v2
Comments
Peter Leow 3-Dec-13 1:54am    
Can we see your code?
Member 10276220 3-Dec-13 2:10am    
this is my code...


<script type="text/javascript">

function myFunction() {

debugger;

var v = document.getElementById('<%=hdnvalue.ClientID%>').value;

$('#div11').append("<div id='" + v + "' style='direction:ltr;display: inline-block; direction: ltr; text-align: left'><table style='width:100px;height:150px;border-style: groove'><tr><td style='background-color:aliceblue'><input type='image' src='Images/close-16.png' id='" + v + "' önClick='myDivFunction(this.id)' align='right'></td></tr><tr><td style='height:50px'><label for='message'>Message Show</label></td></tr><tr><td><textarea rows='5' cols='20' name='message' placeholder='type your message'></textarea></td></tr><tr><td><button type='button' name='button' value='button'>Send</button></td></tr></table><div><div></div>");

var y = parseInt(v) + 1;
document.getElementById('<%=hdnvalue.ClientID%>').value = y;

}


function myDivFunction(obj) {
debugger;
alert(obj);
var x = document.getElementById(obj);

$(x).hide();

return false;
}

</script>
Can you show the code where you are calling myFunction()?
Peter Leow 3-Dec-13 3:04am    
Please append your code to your original question for everyone to view. Not in the comment.

For Hiding a control by its id we normally prefix "#" tag to the control name. Else if you only provide control like $(div) it will hide all the divs in the current page
 
Share this answer
 
Function is...
JavaScript
function myDivFunction(obj) {
    debugger;
    alert(obj);
    var x = document.getElementById(obj);
    
    $(x).hide();
    
    return false;
}

and you are calling it like...
JavaScript
onClick='myDivFunction(this.id)'

Suppose ID is "div1". So function will be called like myDivFunction("div1").

After that in function, you are getting the element like
JavaScript
var x = document.getElementById(obj);
and then hiding it.

But you should directly use the ID like below...
JavaScript
$('#' + obj).hide();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900