Looks interesting but I cannot get it to work?
Did you change the #Box id to the id of your input?
edit: here is the html code:
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> </head> <body> <input id="Box" type="text" /> <button id="Knop1" type="button">Personalized msg</button> <br><br> <button id="Knop2" type="button">Don't Push me!</button> <script> // Knop 2 gives an alert $("#Knop2").click(function(){ alert ("Oi! Push me uh? Push ya right back matey!") }); // Knop 1 gives an alert when clicked. The input is the alert. $("#Knop1").click(function(){ alert ($("#Box").val()) }); $("#Box").submit(function(){ alert ($("#Box").val()) }); // Alert when entering after input is done. $('#Box').keypress(function(e) { if (e.keyCode == 13) { alert($("#Box").val()); } }); </script> </body> </html>
Thank you for pointing that out!
Thanks so much Antay for sharing, I will check it out as soon as
possible!
No problem, we are in this together gl
Thanks, I had just looked up what that was about. I was wondering why my buttons would
work using jquery if they were above the script, but not below. However regular javascript
seemed to work the other way around. This discussion shed some light on it.
How you can use jQuery in order to add logic to HTML elements by specifying an id or class attribute in the tag of the HTML element.
The #id Selector
The id selector uses the # followed by the id of the html item.
$("#test")
The .class Selector
To manipulate items in a specific class of items a period character is used followed by the name of the class.
$(".test")
I donât have a complicated web page, jet, to fully utilise these abilities.
I found your post very useful.
thanks for posting
Cheers
Otto
Thanks to all who have contributed to the conversation on the jQuery element selectors. I donât have much to add other than the fact that a solid knowledge of HTML and CSS3 has helped me a lot to understand jQuery.
To find an element with a specific id, write a hash character, followed by the id of the HTML element:
$("#test")
Example
When a user clicks on a button, the element with id="test" will be hidden:
Example
$(document).ready(function(){
$("button").click(function(){
$("#test").hide();
});
});
To find elements with a specific class, write a period character, followed by the name of the class:
$(".test")
Example
When a user clicks on a button, the elements with class="test" will be hidden:
Example
$(document).ready(function(){
$("button").click(function(){
$(".test").hide();
});
});
I am using below code to make items in one part of list (class = highlight
) 120% with color red on hover
event.
<!doctype html>
<head>
<title>New Work</title>
<script src=âjQuery.jsâ></script>
</head>
<body>
<ul class=âhighlightâ>
<li>Dog</li>
<li>Cat</li>
<li>Elephant</li>
<li>Tiger</li>
</ul>
<p>
<ul>
<li>Canary</li>
<li>Eagle</li>
</ul>
<script>
//Change CSS of element when the mouse enter event happens
$(âul.highlightâ).find(âliâ).on({
mouseenter: function(){
$(this).css(âcolorâ,âredâ);
$(this).css(âfont-sizeâ,â120%â);
},
mouseleave: function(){
$(this).css(âcolorâ,âblackâ);
$(this).css(âfont-sizeâ,â100%â);
},
click: function(){
$(this).css(âbackground-colorâ,âyellowâ);
}
});
</script>
</body>
</html>
So basically it shows you how youâre supposed to select stuff in your code so that you can âjQuery itâ using .insertjsqueryfunction whatever.
$(âinsertelementâ) is used to target those elements on the page.
Putting a # in front of the name of the element will use the ID attribute of the HTML tag to target it.
Putting a . instead will target the entire class.
Iâm not sure if I quite get it but from the stuff Iâve seen so far I think I understand the idea of selecting the element in the right way within the parentheses and then .jQuerying it.
Thank you, I was confused about that.
Using jQuery, you can control elements by class or id. For example:
$( â.surpriseâ ).hide();
such code says that all elements of class surprise will be hidden, i.e you can find element by class or id and do what you want to do with this element.
Thank you so much, I had that exact question
Thatâs good to know. Thanks for sharing.
The best use of value for JQuery can be seen in the case of a website that propagates the data from a database. As development of sites have advanced to use tools that make the servers do most of the work, altering the code has become more and more challenging. A good example of such a challenge can be meet when using, templates for a website. In many cases the code canât be accessed to include the CSS preferred on the element. With JQuery it makes it possible through the wide range of selectors, like a compound CSS selector from JQuery to find the element and alter it to the desired preferences. There are six types of selectors namely,
ID, CLASS, NAME, ATTRIBUTE, COMPOUND CSS, CUSTOM
https://www.tutorialrepublic.com/jquery-tutorial/jquery-selectors.php
Thanks, this was helpful