Syntax error, unrecognized expression: # [object HTMLElement] Error

I created an Overlay section with jQuery.

This I call using <a href="javascript:slide(cms);">.
But I get this error:

Error: syntax error, unrecognized expression: # [HTMLElement object] [HTTP: //localhost//js/jquery-1.9.1.min.js: 4]

Any idea? Here is the slide method:

function slide(content) {
    $('#' + content).show(0);
    $('#' + content).animate({
        left: '0%'
    }, 500);
}
$('.c-close').click(function(){ 
    $('.slide').animate({
        left: '100%'
    }, 500);
    $('.slide').hide(0);
});
+5
source share
3 answers

content.toString() [object HTMLElement]. So, contentthis is an element (or the product of another error in that part of the code that we do not see).

Since contentthis is an element, not its id, you should use $(content), not $('#'+content).

+6
source

The correct answer depends on what content and cms are.

cms, "cms"

DOM, , Id .

<div id="cms" ></div>
<a href="javascript:slide('cms');">

, , :

function slide(element_id) {
    $('#' + element_id).show(0);
    $('#' + element_id).animate({
        left: '0%'
    }, 500);
}

:

cms - , DOm.

.

Javascript:

var cms = $('cms');

function slide(content) {
    content.show(0);
    content.animate({
        left: '0%'
    }, 500);
}

var cms = document.getElementById("cms");

function slide(content) {
    $(content).show(0);
    $(content).animate({
        left: '0%'
    }, 500);
}

HTML:

<a href="javascript:slide(cms);">.

, .

, @dystroy , , . post .

:

<div id="cms"></div>
<a href="#" id="slide">slide</a>
<script>
    (function(){
        $('slide').on('click',function(e){
            e.preventDefault();
            var slideElement = $('div#cms');
            slideElement.show(0);
            slideElement.animate({
                left: '0%'
            }, 500);
        });
    })();
</script>
+3

jQuery, .
, cms <- > <a href="javascript:slide('cms');">

0

All Articles