I have the following button setup:
<div class="BlogManagementDiv">
<button type="button" onclick="fnToggleBox(AddcategoryDiv)">Add Category</button>
<div id="AddcategoryDiv" class="BlogManagementcontainer">
...
</div>
</div>
Note the onclick does this:
fnToggleBox(AddcategoryDiv)
Where it is passing in a reference to the div below:
AddcategoryDiv
I then access the element in the funciton like this:
function fnToggleBox(element)
{
if (!$('#'+element.id).is(":visible")) {
$('#' + element.id).show();
}
else {
$('#' + element.id).hide();
}
}
which I can see is completeley ridiculous, as it already has the element, and there is no need to acces it in this way.
My question is, how to properly access this variable using JQuery.
I know how to do using JavaScript, but am trying to do so using JQuery.
I have tried:
function fnToggleBox(element)
{
if (!element).is(":visible")) {
element.show();
}
else {
element.hide();
}
}
and
function fnToggleBox(element)
{
if (!$element).is(":visible")) {
$element.show();
}
else {
$element.hide();
}
}
but they do not work.
I have googled, but cannot find the answer.
AddcategoryDivto be defined globally... or the syntax/logic errors throughout both attempts.$(element)