Solved

invoke a function call

Posted on 2011-09-28
9
274 Views
Last Modified: 2012-06-21
<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
Comment
Question by:knowlton
  • 5
  • 3
9 Comments
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 100 total points
ID: 36719592
<script type="text/javascript"> $(document).ready(function () {
      Yourfunction();
})
</script
0
 
LVL 5

Author Comment

by:knowlton
ID: 36719694
I only want to call  Yourfunction(  ) based upon the existence of a tag with id of "f1"
0
 
LVL 5

Author Comment

by:knowlton
ID: 36719716
$('#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
 
LVL 5

Author Comment

by:knowlton
ID: 36719746
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 25

Accepted Solution

by:
Kyle Hamilton earned 400 total points
ID: 36719909
$(function(){  // you dont need the document ready stuff

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

alert("hi");

});

});

Should alert hi for all f1 elements on load.
0
 
LVL 5

Author Closing Comment

by:knowlton
ID: 36719953
thx
0
 
LVL 25

Expert Comment

by:Kyle Hamilton
ID: 36720001
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
 
LVL 5

Author Comment

by:knowlton
ID: 36720787
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
 
LVL 25

Expert Comment

by:Kyle Hamilton
ID: 36721665
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now