Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

invoke a function call

Posted on 2011-09-28
9
Medium Priority
?
281 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:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 82

Assisted Solution

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

Author Comment

by:Tom 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:Tom 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Author Comment

by:Tom 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 1600 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:Tom 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:Tom 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This article discusses how to implement server side field validation and display customized error messages to the client.
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)

721 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