Link to home
Start Free TrialLog in
Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on

invoke a function call

<script type="text/javascript">
    $(document).ready(function ()
    {
        $('#f1').css("border", "3px solid blue");
    });

</script>

instead of changing the css border style, I want to call a javascript function.  How do I do this?
SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tom Knowlton

ASKER

I only want to call  Yourfunction(  ) based upon the existence of a tag with id of "f1"
$('#f1').Yourfunction();

I don't think that syntax is valid, but it expresses my intent.

In plain English it would say "Select all elements with id of f1 and then call Yourfunction( ) on each one (assuming you find at least ONE match)
I guess this works:

 $(document).ready(function ()
    {
        if ($('#f1').length > 0)
        {
            somefunction();
        }
    });

    function somefunction() {alert("hi");}


The alert message appears when I hit the page.


Is there a better / cleaner way to do this?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thx
Just as an aside, if you have more than one f1, you should use a class not id. There should only be one unique id per page.

Glad I could help,
Cheers.
Thank you!

btw, are you familiar with jQuery plugin "qtip" ??

http://craigsworks.com/projects/qtip/docs/reference/#content

I am trying to add an image to the callout
I don' t know it off the top of my head. But you should post a new question and I can look into it...