Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

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?
0
Tom Knowlton
Asked:
Tom Knowlton
  • 5
  • 3
2 Solutions
 
leakim971PluritechnicianCommented:
<script type="text/javascript"> $(document).ready(function () {
      Yourfunction();
})
</script
0
 
Tom KnowltonWeb developerAuthor Commented:
I only want to call  Yourfunction(  ) based upon the existence of a tag with id of "f1"
0
 
Tom KnowltonWeb developerAuthor Commented:
$('#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)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Tom KnowltonWeb developerAuthor Commented:
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?
0
 
Kyle HamiltonData ScientistCommented:
$(function(){  // you dont need the document ready stuff

$("f1").each(function(){

alert("hi");

});

});

Should alert hi for all f1 elements on load.
0
 
Tom KnowltonWeb developerAuthor Commented:
thx
0
 
Kyle HamiltonData ScientistCommented:
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.
0
 
Tom KnowltonWeb developerAuthor Commented:
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
0
 
Kyle HamiltonData ScientistCommented:
I don' t know it off the top of my head. But you should post a new question and I can look into it...
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now