0

I am making a page with three buttons and have three different text fields. I am trying to use this function:

function funName() {
    $(this).show({
      'left': '-=700px'
    });
}

for three different $("#IDs"). to display different boxes of text. Iv tried

$("btnElement").click(function() {
   $("#ID1").funName();
});

Thank you for your help.

1 Answer 1

1

The way to define a new jQuery method is by definining jQuery.fn.methodName:

jQuery.fn.funName = function() {
    $(this).show({
      'left': '-=700px'
    });
}
Sign up to request clarification or add additional context in comments.

2 Comments

or pass the target element into the function: function funName($el){ $el.show(...) }. $('bin').click(function(){ funName($('#id')) });
@Mike That's what I was going to answer first, but I thought it would be more interesting to show how to do what he wrote.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.