Why the class.click method doesn't work? - html

I am beginner at web programming. I am trying to assign click method to a className. But it doesn't work and no solution on the internet worked for me. How can I fix this problem?
My simple code:
<html>
<head>
<title>ada</title>
<style>
.menu{background-color:green;}
</style>
<script>
$(document).on("click",".menu",function()
{
alert("Hello World");
});
</script>
</head>
<body>
<input type="button" class="menu" value="click!" />
</body>
</html>

Add jquery library file
http://code.jquery.com/jquery-1.8.3.min.js
$(document).on("click",".menu",function()
{
alert("Hello World");
});
https://jsfiddle.net/uq8zf0m4/

<html>
<head>
<title>ada</title>
**<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"> </script>**
<style>
.menu{background-color:green;}
</style>
<script>
$(document).on("click",".menu",function()
{
alert("Hello World");
});
</script>
</head>
<body>
<input type="button" class="menu" value="click!" />
</body>
</html>

1st. Make sure you're referencing the Jquery api in your scripts tag in the head elements.
2nd. A good tutorial and easy to read reference for beginners
http://www.w3schools.com/jquery/event_click.asp

Related

How do I remove document.write in html output?

<html>
<head>
<title>My HTML</title>
<script type="text/javascript"></script>
document.write("Hello World");
</head>
<body>
</body>
</html>
How Do I remove the document.write part of the output? My chrome output is document.write("Hello World");
I just want to output Hello World on Chrome.
You need to move the closing script tag to be after the document.write("Hello World") so that the document.write() is encased within the script tag. e.g.
<html>
<head>
<title>My HTML</title>
<script type="text/javascript">
document.write("Hello World");
</script>
</head>
<body>
</body>
</html>

How to get the Vue's element's child DOM?

How to get the Vue's element's child DOM?
I have bellow code, I want to get the <div>'s <input> element.
var vm = new Vue({
el: '#box',
data: {
pick: true,
a: 'a'
}
})
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="box">
<input type="radio" v-model="pick" :value="a">
</div>
<script type="text/javascript" src="https://cdn.bootcss.com/vue/2.5.13/vue.min.js"></script>
<script type="text/javascript" src="https://cdn.bootcss.com/vue-resource/1.3.4/vue-resource.min.js"></script>
<script type="text/javascript" src="index.js"></script>
</body>
</html>
How can I get that in Vue.js? Or in the Console?
I think you should tell us what functionality do you want to realize.
For your question:in vue.js there is ref binding to get the reference of DOM elements.
//html
<div id="box">
<input ref="domOfInput" type="radio" v-model="pick" :value="a">
</div>
//js code
vm.$refs.domOfInput will be the DOM node

About DIVs (Hiding and Showing not Java)

<div id="abc" style="display: none;"><h1>abc</h1></div>
Hello! I hide the div but I want to see when I type it #abc I can't see this text.
In case people want to do it without having to resort to JavaScript, the CSS solution is to use the :target pseudo class, as mentioned in the comments.
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<style>
#abc {display:none}
#abc:target {display:block}
</style>
</head>
<body>
<div id="abc"><h1>abc</h1></div>
</body>
</html>
Please find below sample as per your requirement.
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
if(window.location.href.indexOf("#abc")!=-1)
{
//alert("Page is loaded");
document.getElementById("abc").style.display="block";
}
}
</script>
</head>
<body onload="myFunction()">
<h1>Hello World!</h1>
<div id="abc" style="display: none;"><h1>abc</h1></div>
</body>
</html>
This is how you can do it using jquery:
var url = "https://abcdefgh.carrd.co/#abc";
var hash = url.substring(url.indexOf("#"));
// You can use
// var hash = window.location.hash;
// but i need to write the url to show you that is working.
if ($( hash ).length) { //check if div exists
$( hash ).show();
}
#abc, #cde
{
display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="abc">ABC</div>
<div id="cde">CDE</div>
That should do it:
if(window.location.href.indexOf("#abc")!=-1) {
document.getElementById("abc").style.display="block";
}}

"Tag start is not closed" when using Handlebars.js

I'm getting an error that says "Tag start is not closed" in the following HTML code after the input tag. I can't seem to figure out why since I am using the Handlebars syntax properly. Can someone help me out please?:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="todo">
</div>
<script id="item-template" type="text/x-handlebars-template">
// Your code goes here
<div>
<input id="todo-complete" type="checkbox" {{#if completed}} "checked" {{/if}}>
<label>{{title}}</label>
</div>
</script>
<script src= "underscore.js"> </script>
<script src="handlebars-v1.3.0.js"> </script>
<script src="backbone.js"> </script>
<script src="jquery-1.11.1.js"> </script>
<script src="main.js"> </script>
</body>
You IDE doesn't understand Handlebars syntax, hence reporting a Error, which you should ignore.

use of head tag in between div tag

this is sample code i tried n its working
<html>
<head>
<style>
<!--
.execute { background-color: red; height: 25px; }
-->
</style>
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js">
</script>
<!-- Let's register a onClick handle for any .execute div. -->
</head>
<body>
<div class="execute">
<head>
<script>
dojo.ready(function() // Dojo will run this after being initialized
{
// Get A list of all tags with id execute and add a event onClick
dojo.query(".execute").connect("onclick", function(evt)
{
alert("Event triggered!");
// ...
});
});
</script>
</head>
<body>
Click me 1
</body>
</div>
<br /><br />
<div class="execute">Click me 2</div>
</body>
</html>
but if i merge it in another code it highlights and as invalid code. what does it means?
Ther are several code issues. double <head> tags, HTML elements after the <body> tag.
cleaned up code:
<html>
<head>
<style>
.execute { background-color: red; height: 25px; }
</style>
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js"></script>
<script>
dojo.ready(function() { // Dojo will run this after being initialized
// Get A list of all tags with id execute and add a event onClick
dojo.query(".execute").connect("onclick", function(evt) {
alert("Event triggered!");
// ...
});
});
</script>
</head>
<body>
<div class="execute">Click me 1</div>
<br><br>
<div class="execute">Click me 2</div>
</body>
</html>
<head> should only appear once, directly under the <html>, and not within <body>.
Exceptions to this are iframes embedded within existing pages, which have their own document structure.
Just remove the second <head>.
Why do you have two heads? <script>s don't have to be in <head>s.
You should only have a single <head> in your document.
The structure of an HTML page should be as follow:
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>
Although they do not have to be, most people put script tags within the opening and closing header tags. For example:
<html>
<head>
<title></title>
<script>
<!--This is where all your functions should be.-->
</script>
</head>
<body>
</body>
</html>