Solved

invoke a function call

Posted on 2011-09-28
9
276 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
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 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
 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to dynamically set the form action using jQuery.
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…

776 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