Solved

invoke a function call

Posted on 2011-09-28
9
275 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

DOM Attributes and Properties treatment with jQuery 1.6 by Ivo Stoykov jQuery (http://jquery.com/) 1.6 introduces .prop() (http://api.jquery.com/prop/) and .removeProp() (http://api.jquery.com/removeProp/) methods which allow modifying or removi…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
The viewer will learn how to dynamically set the form action using jQuery.
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)

920 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

11 Experts available now in Live!

Get 1:1 Help Now