0

I use different javascript function. The problem is that they have the same name so they overwrite each other. I would like to put a different name but so far it didn't work.

Here one of the function and how I use it:

<script type="text/javascript">     
    $(function() {
        $('#datepicker').multiDatesPicker({
            altField: '#date',
            dateFormat: "yy-mm-dd",
        });
</script>

<div id="datepicker"></div>

The other function start like this too $(function() {} and use the same way <div id="date"></div>

I try to put $(function name() but it didn't work. Do you have any idea? Thanks

3
  • That function is anonymous, so it can't be overwritten. Commented Aug 2, 2013 at 7:13
  • Do you mean you have a library conflicting with the $ syntax? If so, use noConflict() : api.jquery.com/jQuery.noConflict Commented Aug 2, 2013 at 7:14
  • yes it's this problem but i can't find the way to solve it Commented Aug 2, 2013 at 8:35

2 Answers 2

3

This is a call to $ (in your case, it's jQuery), with a single argument, which happens to be an anonymous function. It doesn't have a name, and having more than one occurrence of this pattern will not "overwrite" the previous:

$(function() {
    // ...
});

Passing a function to $ is just shorthand for $(document).ready(). If you need more than one, you should be able to simply combine them:

$(function() {
    // Initialise your date picker
    // Do some other stuff
});
Sign up to request clarification or add additional context in comments.

4 Comments

if I combine them only the first one work and not the second one like: $(function() { $('#datepicker').multiDatesPicker({...}); $( "#dialog" ).dialog({..}); });
Then something is wrong with the second one. Does it work if you remove the first one?
yes it works. If I put the second one on top it's the first one (become second) which stop to work
I try to use it, but I need jquery code also so it seems doesn't work correctly, here the link in case jsfiddle.net/GNjtA/1
0

that function is shorthand for $(document).ready() which is just a binding to the ready event of the document. all that means is you can have as many of them as you want without overwriting eachother.

see the jsfiddle

    $(function()
  {
      alert('func1');
  });
$(function()
  {
      alert('func2');
  });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.