EXAMPLE JQUERY

In this example I am going to change the size and the color of the some division inside of this html
Step 1

Always is good idea to work with CSS, because you can generalize the style for many element as you want. then the first section will be

<style>
  .high { width:50px; height:70px; float:left; margin: 2px;
        background:#003300; cursor:pointer; }
  .low { width:50px; height:35px; float:left; margin:2px;
        background:#ff0000; cursor:pointer; }
  #back {   float:left; margin:30px;
        background:#0000ff; cursor:pointer; }
    </style>

This time i have 2 class call them HIGH and LOW and 1 ID call BACK , remember is a good practice use class when you are going to use the style for more than 1 element. Use Id when you are going to use the style just for 1 element.

Step 2
After do this now we insert the link to JQUERY

Remember this insert should be in the head section of the document. I insert the minimized version because I am not going to debugging it.

Now at the body we have 6 division with class=”high” , 4 division with class=”low” and 1 division with id=”back”

we are going to modify the divisions with class “high” and ” low”

Step 3

Insert the JavaScript code to use Jquery

function rgbtohex(hex)
{
   texto= “0123456789ABCDEF”;
      num = texto.charAt((hex-hex%16)/16)  + texto.charAt(hex%16);
   if (num == 0)
       return “00”;
  else{
  if (num > 255)
      return “FF”;
     else
       return num ;}}

the routines from above 2 routine are used to convert the RGB code to Hexa code. When you get

the element color style by Jquery , the code is returned in RGB format RGB(NNN,NNN,NNN), Then we need a subroutine to convert them.

function sumhex(valor,incre)
{suma=parseInt(valor,16)+incre;
 if (suma >16777216)
      suma=”000000″;
return suma;}

The routine of above is used to add 16 to the color of each division, in this way we can change the color in cycle way.

$(“.low”).mouseover(  function () {
     var bckl= $(this).css(“backgroundColor”);
  var hex = eval(bckl);
      bckl=  sumhex(hex,33).toString(16);
      $(this).height(70)
             .css(“backgroundColor”, bckl);

In this routine we do use jquery, The first thing different is the use of the $ sign , this is a shortcut to call JQUERY routines , this is the most common way to use jquery.

The first parameter in the Jquery call is the element which is going to be affect by this call. In this case I am using Class “Low” , can you see the point (.) at the beginning of the string? This mean for Jquery that the element(s) affected are going to be those with class .nameclass.

You can use ID of the element(s) , for this case you start the string with # sign. Note that is same notation for CSS.

After this Jquery use the the trigger event in this case is the MOUSEOVER. You can set property that you want to change in the element. Inside the event you can call a function or create a function insde as it is show in the example.

Another thing you note is the instruction

$(this).css(“backgroundColor”);

Now you now whet $ sign means, but the parameter “THIS” is a relative term. “THIS” is making reference to the element (in this case class LOW) which is being affected for the call of JQUERY.

Last thing “css()” is used to get a style or change a style of the element.

In order to get style use:

$(this).css(“Property”);

In order to change style use

$(this).css(“Property”, “value”);

value can be hexa format.
See the example
THE COMPLETE CODE IS

<html>
<head>
<!– example the jquery  cgange background color and high of the division –>
  <style>
  .high { width:50px; height:70px; float:left; margin: 2px;
        background:#003300; cursor:pointer; }
  .low { width:50px; height:35px; float:left; margin:2px;
        background:#ff0000; cursor:pointer; }
  #back {   float:left; margin:30px;
        background:#0000ff; cursor:pointer; }
    </style>
 <!– include jqery library –>
<script src=”http://code.jquery.com/jquery-latest.min.js”></script>
</head>
 
<body>
<!– jquery  modify  division with same class or id , use id for  just one element or class for more than 1 –>
<div id=”back”>
 <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>

  <div></div>
  <div></div>
  <div></div>
</div>
<script>
//this function  is created for recive eval rgb color
function rgb(a,b,c)
      {total= rgbtohex(a)+rgbtohex(b)+rgbtohex(c);
    return total;}
// convert numbre by number rgb to hexa 
function rgbtohex(hex)
{
   texto= “0123456789ABCDEF”;
      num = texto.charAt((hex-hex%16)/16)  + texto.charAt(hex%16);
   if (num == 0)
       return “00”;
  else{
  if (num > 255)
      return “FF”;
     else
       return num ;}}
// add  1 decimal number to 1 hexa number  
function sumhex(valor,incre)
{suma=parseInt(valor,16)+incre;
 if (suma >16777216)
      suma=”000000″;
return suma;}

// $ is a  shortcut for jquery

//  change high and color for division with class low  when mouse is over the division
$(“.low”).mouseover(  function () {
     var bckl= $(this).css(“backgroundColor”);
  var hex = eval(bckl);
      bckl=  sumhex(hex,33).toString(16);
      $(this).height(70)
             .css(“backgroundColor”, bckl);
    });
//  change high and color for division with class high when mouse is over the division

 $(“.high”).mouseover(  function () {
   var bckl= $(this).css(“backgroundColor”);
  var hex = eval(bckl);
      bckl=  sumhex(hex,33).toString(16);
      $(this).height(35)
              .css(“backgroundColor”, bckl);
    });

//  change high and color for division with class low  when mouse is out the division

 $(“.low”).mouseout(  function () {
 var bckl= $(this).css(“backgroundColor”);
  var hex = eval(bckl);
      bckl=  sumhex(hex,33).toString(16);

      $(this).height(35)
             .css(“backgroundColor”, bckl);
    });
 
//  change high and color for division with class high  when mouse is out the division

 $(“.high”).mouseout(  function () {
     var bckl= $(this).css(“backgroundColor”);
  var hex = eval(bckl);
      bckl=  sumhex(hex,33).toString(16);
  
$(this).height(70).css(“backgroundColor”, bckl);
             
    });</script>
</body>
</html>

This entry was posted in Javascript,Jquery and tagged , , , . Bookmark the permalink.

74 Responses to EXAMPLE JQUERY

  1. Found your web site via msn the other day and absolutely love it. Keep up the truly amazing work.

  2. This is a superb post and may be one that ought to be followed up to see what goes on

    A chum e mailed this link the other day and I will be excitedly awaiting your next content. Keep on on the top quality work.

  3. Located your blog via google the other day and absolutely enjoy it. Keep up the good work.

  4. WP Themes says:

    Amiable post and this fill someone in on helped me alot in my college assignement. Say thank you you for your information.

  5. Genial post and this enter helped me alot in my college assignement. Say thank you you as your information.

  6. Great post, I have been waiting for that.

  7. Sorry for my bad english. Thank you so much for your good post. Your post helped me in my college assignment, If you can provide me more details please email me.

  8. Medical Jobs says:

    Terrific work! This is the type of information that should be shared around the web. Shame on the search engines for not positioning this post higher!

  9. Naturally, what a excellent internet site and informative posts, I’ll add backlink – bookmark this site? Regards,
    Reader.

  10. Pretty nice post. I just stumbled upon your blog and wanted to say that I have really enjoyed browsing your blog posts. In any case I’ll be subscribing to your feed and I hope you write again soon!

  11. Hey, I attempted to e-mail you pertaining to this post but aren?t able to attain you. Please e-mail me when get a moment. Thanks.

  12. Wow! what an notion ! What a concept ! Stunning .. Amazing ? I typically don?t post in Blogs but your weblog compelled me to, amazing operate.. beautiful ?

  13. Great work keep it coming, best blog on earth

  14. maria andros says:

    It is your turn to come up with that concept that clarifies dilemmas with so well.

  15. potenzmittel says:

    There is clearly a whole lot to know about this. I think you created some good points in Characteristics also.
    Keep working , terrific occupation!

  16. It is 2nd incident that I’m scanning something about modifying web sites using the method. It appears that you are an super expert blogger. Your publish is definitely an excellent Instance of why I keep on coming back to study your excellent quality content material which is eternally updated.

  17. As being a Newbie, I’m constantly looking on-line for articles or blog posts that will help me. Thank you

  18. This is really a seriously beneficial go through for me, Ought to admit that you might be one of the most effective bloggers I ever noticed.Thanks for posting this informative write-up.

  19. Wow! what an thought ! What a concept ! Gorgeous .. Astounding …

  20. This is such a great resource that you are providing and you give it away for free. I enjoy seeing websites that understand the value of providing a prime resource for free. I truly loved reading your post. Thanks!

  21. Hi, I can not realize how you can add your website in my rss reader. Can you Aid me, please

  22. backlinks says:

    Please, are you able to Pm me and tell me few extra thinks about this, I’m genuinely fan of your blog… 34

  23. maria andros says:

    Thanks for the post, keep posting stuff

  24. abnehmpillen says:

    To all the over commentors. Blogs can be much better to examine in case you can keep Your comments easy and also to the point. No-one likes to examine large feedback when the concept may be conveyed using a not as lengthy comment

  25. Superb blog post, I have book marked this internet site so ideally I’ll see much more on this subject in the foreseeable future!

  26. Hi there, I found your blog via Google although searching for initial assist to get a coronary heart assault and your post
    looks incredibly fascinating for me.

  27. dai dai hua says:

    There’s obviously a lot to understand about this. I believe you created some great points in Functions also.
    Keep working , excellent career!

  28. To commence earning dollars with your blog, in the beginning use Google adsense but steadily as your traffic
    increases, keep adding increasingly more money producing programs for your site.
    thanks !! very useful submit!

  29. doofmann says:

    I maintain listening towards the information talk about getting free on the internet grant applications so I’ve been
    looking about for the best internet site to obtain one.
    Thank you for the support!

  30. I like when you talk about this type of stuff in your blog. Perhaps could you continue to do this?

  31. Visitors Mayhem Review- the content articles on this article is genuinely a single of probably the most efficient substance that i?ve in fact are out there throughout. I really like your write-up, I will are available once more to verify for new posts.

  32. Wow! Thank you! I always wanted to create in my internet site some thing like that. Can i get part of your
    post to my weblog?

  33. webdesign says:

    I keep listening to the news speak about getting free online grant applications so I have been looking around for the best site to get one. Thank you for your help!

  34. webdesigner says:

    Greetings, this is a truly absorbing Internet weblog and I have cherished studying numerous with the content material and posts contained on the web web site, keep up the outstanding do the job and need to go through a great deal far more stimulating articles or blog posts in the long term.

  35. yeah,I just believed you might want to realize that your weblog is messed up when you view it on my iphone. I?m not sure if it’s something to try and do with my telephone?s browser or your web page? just saying…

  36. Wow!! I love what you might be doing! I require to relook at screen toaster! Informative and fascinating submit!!! keep it up..

  37. Hi and thanks for publishing this. It addressed a large amount of questions in which I had. Thank you.

  38. Hello! I know this is kind of off topic but I was wondering which blog platform are you using for this site? I’m getting sick and tired of WordPress because I’ve had problems with hackers and I’m looking at alternatives for another platform. I would be great if you could point me in the direction of a good platform.

  39. Joe Johnson says:

    Your blog constantly makes me think, I have just bookmarked it!

  40. Belinda says:

    I found your site from altavista and it is eye-popping. Thank you for sharing such an incredible article…

  41. John Cook says:

    You gave tremendous positive points there. I did a search on the topic and found most peoples will agree with your blog.

  42. Gregory says:

    What I want to know is why I should care? I mean, not to say that what youve got to say isnt important, but I mean, its so generic. Everyones talking about this man. Give us something more, something that we can get behind so we can feel as passionately about it as you do.

  43. Alex says:

    You have some honest ideas here. I done a research on the issue and discovered most peoples will agree with your blog. After that early period, the Beatles evolved considerably over the years.

  44. This is the suitable blog for anybody who desires to find out about this topic. You realize so much its virtually laborious to argue with you (not that I actually would want…HaHa). You definitely put a brand new spin on a topic thats been written about for years. Nice stuff, simply nice!

  45. George says:

    You really make it seem so easy with your presentation but I find this topic to be really something which I think I would never understand. It seems too complicated and very broad for me. I am looking forward for your next post, I will try to get the hang of it!

  46. Cathey Utz says:

    Kudos for posting such a useful weblog. Your weblog isn’t only informative and also extremely artistic too. There usually are very couple of individuals who can write not so simple articles that creatively. Keep up the good work !!

  47. Hey very cool web site!! Man .. Beautiful .. Amazing .. I’ll bookmark your blog and take the feeds also…I am happy to find numerous useful info here in the post, we need work out more techniques in this regard, thanks for sharing. . . . . .

  48. A powerful share, I simply given this onto a colleague who was doing a bit evaluation on this. And he in truth purchased me breakfast as a result of I discovered it for him.. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for spending the time to discuss this, I feel strongly about it and love reading extra on this topic. If potential, as you change into expertise, would you mind updating your weblog with extra details? It’s highly helpful for me. Huge thumb up for this weblog put up!

  49. I found your blog website on google and examine a few of your early posts. Proceed to maintain up the superb operate. I simply further up your RSS feed to my MSN News Reader. Seeking forward to studying more from you later on!…

  50. Nice post. I study one thing tougher on completely different blogs everyday. It can all the time be stimulating to read content material from different writers and practice just a little one thing from their store. I’d desire to make use of some with the content on my weblog whether or not you don’t mind. Natually I’ll provide you with a link on your internet blog. Thanks for sharing.

  51. Hello there, I found your blog via Google while searching for a related topic, your site came up, it looks great.I’ve bookmarked it in my google bookmarks

  52. Poker Forums says:

    A formidable share, I just given this onto a colleague who was doing a bit analysis on this. And he in actual fact purchased me breakfast as a result of I found it for him.. smile. So let me reword that: Thnx for the treat! But yeah Thnkx for spending the time to discuss this, I feel strongly about it and love studying extra on this topic. If attainable, as you develop into expertise, would you thoughts updating your weblog with more details? It is highly helpful for me. Massive thumb up for this weblog submit!

  53. Hi. I needed to drop you a quick note to impart my thanks. I have been following blog for a month or so and also have plucked up a heap of good info as well as relished the way you’ve structured your site. I’m seeking to run my very own blog nevertheless I think its too general and that i want to focus more about smaller topics.

  54. Pretty section of content. I just stumbled upon your blog and in accession capital to assert that I acquire actually enjoyed account your blog posts. Any way I’ll be subscribing to your augment and even I achievement you access consistently fast.

  55. Arnold Leber says:

    Thank you for the auspicious writeup. It in fact was a amusement account it. Look advanced to more added agreeable from you! By the way, how could we communicate?

  56. Hey admin, quite informative blog post! Pleasee continue this awesome work..

  57. poker says:

    very good post, i actually love this web site, keep on it

  58. ebooki says:

    The very crux of your writing while sounding agreeable originally, did not really settle properly with me personally after some time. Somewhere within the paragraphs you managed to make me a believer unfortunately only for a short while. I however have a problem with your jumps in logic and you would do well to help fill in those gaps. In the event that you actually can accomplish that, I will definitely be impressed.

  59. Excellent beat ! I wish to apprentice while you amend your site, how could i subscribe for a blog website? The account helped me a acceptable deal. I had been a little bit acquainted of this your broadcast offered bright clear idea

  60. You actually make it seem so easy with your presentation but I find this matter to be actually something that I think I would never understand. It seems too complicated and extremely broad for me. I am looking forward for your next post, I’ll try to get the hang of it!

  61. Great article. Waiting for more.

  62. Thanks for taking the time to talk about this, I feel fervently about this and I take pleasure in learning about this topic. Please, as you gain information, please update this blog with more information. I have found it very useful. There have to be charging stations everywhere.

  63. Hi buddy, your blog’s model is easy and clean and i like it. Your blog articles or blog posts are superb. Please keep them coming. Greets!!!

  64. Very nice post. I just stumbled upon your blog and wanted to say that I’ve really enjoyed surfing around your blog posts. In any case I will be subscribing to your rss feed and I hope you write again soon!

  65. Jose Dreps says:

    Wonderful work! This is the type of information that should be shared around the net. Shame on the search engines for not positioning this post higher! Come on over and visit my website . Thanks =)

  66. Sensational info. I look forward to seeing more.

  67. Solid post, nice work. It Couldn’t be written any improved. Reading this post reminds me of my previous boss! He usually kept babbling about this. I will forward this article to him. Pretty certain he will have a superb read. Thanks for sharing!

  68. F*ckin’ awesome things here. I’m very glad to see your post. Thanks a lot and i am looking forward to contact you. Will you kindly drop me a e-mail?…

  69. Was amused from the floor up. Will sticker around a bit more for a good read.

  70. msm says:

    Can you please send me a mail. I genuinely like your style.

  71. When will you post again ? Been looking forward to this !

  72. 888casino says:

    After study a couple of of the blog posts in your website now, and I actually like your method of blogging. I bookmarked it to my bookmark website list and can be checking again soon. Pls take a look at my website online as well and let me know what you think.

  73. Perfect work you have done, this web site is really cool with superb info .

  74. Teri Klein says:

    Usually I do not read article on blogs, but I wish to say that this write-up very forced me to try and do it! Your writing style has been amazed me. Thanks, very nice post…..

Leave a Reply