JavaScript how to write a function in jquery [duplicate] write function jquery,write jquery function in js file,write

You should add a data attribute to your markup, linking the triggering element (#standard etc) to the table you want to hilight. In general, it's wise to semantically link related elements so that code can be as generic as possible, and apply to a wide range of elements on your page:

<div id="standard" data-table="#table-one">
...
</div>

Now, all of your elements can use the same handlers:

$(function () {

  $('#basic, #standard, #pro, #expert').mouseOver(function () {
    $($(this).data("table")).css({ boxShadow : "0 0 5px 3px rgba(100,100,200,0.4)" });
  }).mouseout(function () {
    $($(this).data("table")).css({ boxShadow : "0 0 0 0" });
  });

});

note: You don't need to wrap each and every block in a $(function () { }). One, around the whole blob of code you posted, would suffice.

Answer:1

Cleaned and shortened your code a bit:

$(function(){
    $('#basic').mouseover(function(){
        animateIn('#table-one');
        }).mouseout(function(){
        animateOut('#table-one');
        });
    $('#standard').mouseover(function(){
        animateIn('#table-two');
        }).mouseout(function(){
        animateOut('#table-two');
        });
    $('#pro').mouseover(function(){
        animateIn('#table-three');
        }).mouseout(function(){
        animateOut('#table-three');
        });
    $('#expert').mouseover(function(){
        animateIn('#table-four');
        }).mouseout(function(){
        animateOut('#table-four');
        });
    function animateIn(id) {
        $(id).css({ boxShadow : "0 0 5px 3px rgba(100,100,200,0.4)" });
    }
    function animateOut(id) {
        $(id).css({ boxShadow : "0 0 0 0" });
    }
});

Should work, tell me if it does not

Answer:2

Try this out

function mouseIn(target) {
    $('#table-' + target).css({ boxShadow : "0 0 5px 3px rgba(100,100,200,0.4)" });
}

function mouseOut(target) {
    $('#table-' + target).css({ boxShadow : "0 0 0 0" });
}

Then use them as such:

$('#expert').hover(
    function() {
        mouseIn('four');
    }, function() {
        mouseOut('four');
    }
);

EDIT: A more overkill (weeehooo) solution would be to iterate over it all and set it up:

var objs = {'basic': 'one', 'standard': 'two', 'pro': 'three', 'expert': 'four'};
for (var key in objs) {
    $('#' + key).hover(
        function() {
            $('#table-' + objs[key]).css({ boxShadow : "0 0 5px 3px rgba(100,100,200,0.4)" });
        }, function() {
            $('#table-' + objs[key]).css({ boxShadow : "0 0 0 0" });
        }
    );
}
Answer:3

I just found that I can use $('form').prop(name) to get input with that name within the form. Then I experimented on other tags, and this won't work for div and body. Now I don't have a way to tell if ...

I just found that I can use $('form').prop(name) to get input with that name within the form. Then I experimented on other tags, and this won't work for div and body. Now I don't have a way to tell if ...

  1. form form method property

It's certainly noticeable how delayed a YouTube video page can load when on a slower computer or laptop. Things such as the sidebar, comments, the uploaders Icon and other image elements. My script ...

It's certainly noticeable how delayed a YouTube video page can load when on a slower computer or laptop. Things such as the sidebar, comments, the uploaders Icon and other image elements. My script ...

  1. how to increase youtube page size
  2. how to increase youtube page rpm

Can anyone suggest a regex that will test if the first word of a string is a day of the week. e.g. "Tuesday, July 16" So far I have this: /^((Monday)|(Tuesday)|(Wednesday)|(Thursday)|(Friday)|(...

Can anyone suggest a regex that will test if the first word of a string is a day of the week. e.g. "Tuesday, July 16" So far I have this: /^((Monday)|(Tuesday)|(Wednesday)|(Thursday)|(Friday)|(...

  1. regex first word before space
  2. regex first word in string
  3. regex first word after match
  4. regex first word match
  5. regex first word of each line
  6. regex first word before comma
  7. regex first word
  8. regex first word after space
  9. regex first word before character
  10. regex first word only
  11. regex first word after comma
  12. regex first word javascript
  13. regex first occurrence of word
  14. regex get first word
  15. regex get first word before space
  16. regex remove first word
  17. regex extract first word
  18. regex match first word in line
  19. regex select first word
  20. regex ignore first word

I'm using the iterate mediator for saving files. For this I need a counter for the iterations. I tried to create an property outside of the iteration and use the script mediator to count the ...

I'm using the iterate mediator for saving files. For this I need a counter for the iterations. I tried to create an property outside of the iteration and use the script mediator to count the ...

  1. wso2 esb iterate counter