Uncaught ReferenceError: $ is not defined in javascript but idk why [duplicate] - javascript

This question already has answers here:
JQuery - $ is not defined
(36 answers)
Closed 21 days ago.
I want to test a html,css,javascript code but it don't work and I don't know why
enter image description here
Make a random name winner with personnalized input name and pop in the screen the winner of the random system.

Jquery not imported or loaded correctly..
From cdn:
<script src="https://code.jquery.com/jquery-3.6.3.min.js" integrity="sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU=" crossorigin="anonymous"></script>
Insert this tag befor your custom script..

Related

Jquery load HTML that includes js file not working [duplicate]

This question already has answers here:
jquery .load with script in it
(1 answer)
how to jQuery .load() with script tags
(1 answer)
jQuery .load() call doesn't execute JavaScript in loaded HTML file
(13 answers)
Closed 2 years ago.
I'm trying to load html using jqyery. That HTML includes a js file, and every time I try to load it it doesn't execute js file included in it. But when I write the script inside the html page it works fine.
What doesn't work:
<link rel="stylesheet/less" href="/categories/categories.less">
<div id="categories">
</div>
<script type="module" src="/categories/categories.js"></script>
What does work:
<link rel="stylesheet/less" href="/categories/categories.less">
<div id="categories">
</div>
<script >
console.log('categories has been loaded');
</script>

load page using javascript on div makes functions Uncaught error [duplicate]

This question already has answers here:
Can scripts be inserted with innerHTML?
(26 answers)
Closed 2 years ago.
In Page index.php i have this code to load a page on div. The idea is have a master template and load dynamically content on a div.
<script>
async function loadPage(page){
var page = page;
let url = page + '.php';
content.innerHTML = await(await fetch(url)).text();
}
</script>
<button onclick="loadPage('settings')">Settings</button>
<button onclick="loadPage('users')">Users</button>
<div id="content"></div>
Each page has his own html and javascripts, settings.php has html and some javascript functions:
<script>
function helloWorld(){
alert('helloWorld');
}
</script>
<button onclick="helloWorld()">Click</button>
The page load fine, but i cant excecute the helloworld() and i get this error on console:
(index):1 Uncaught ReferenceError: helloWorld is not defined
at HTMLAnchorElement.onclick ((index):1)
, but if the function is on index.php runs fine.
My guess is javascript not detect the new function loaded.
There is a thread here that explains the various options and that innerHTML can't be used to inject JavaScript.

Can you use JavaScript inside an email, which is sent using Python? [duplicate]

This question already has answers here:
Is JavaScript supported in an email message?
(11 answers)
Closed 5 years ago.
Can you use JavaScript inside an email, which is sent using Python?
My aim is to send a working clock inside an email.
I am trying to use Python to do so. I am using IDLE and the Python libraries stmplib, email and html2text to send emails. My code looks like the code shown below. I omitted some details (style and script) as they are unimportant.
me = "my.email#gmail.com"
you = "my.email#gmail.com"
msg = MIMEMultipart('alternative')
msg['Subject'] = "Clock"
msg['From'] = me
msg['To'] = you
html = """\
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Clock</title>
<style></style>
</head>
<body>
<div class="clock">
<p class="clockhour">HH</p>
<p class="clocksym1">:</p>
<p class="clockminute">MM</p>
<p class="clocksym2">:</p>
<p class="clocksecond">SS</p>
</div>
<script type="text/javascript"></script>
</body>
</html>
"""
text = html2text(html)
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
msg.attach(part1)
msg.attach(part2)
s = SMTP('smtp.gmail.com:587')
s.ehlo()
s.starttls()
s.login("my.email#gmail.com", "my password")
s.sendmail(me, you, msg.as_string())
s.quit()
The full version of the HTML in this code gives me a properly functioning clock, but if I attempt sending it to myself using Gmail I receive a different result.
Viewing the HTML:
In Gmail:
This shows, that parts of the CSS load, but others like the font or the font size don't. It also shows that the JavaScript does not load. (Normally viewing the HTML code in a browser gives a functioning clock, while in an email doesn't.)
Is there a way to send an email with this clock?
Short Answer: No. You can't use JavaScript for email template.
Tricky way: You can work on relevant file and get the parsed value in your template file using server side language.
Example:
clock.js
// code for js
template.php
// echo the value
// The value is rendered in html and works in email template too.
But this case is not suitable for you as you're trying to implement countdown clock. This is suitable only for static value.
However, linking to external page content will help you to show the timer.
For your case, You may try using http://motionmailapp.com/
Hope, this helps!
javascript is unsupported in email html, but at least you can place a link to the page with clock countdown.

How to combine php, html and javascript? [duplicate]

This question already has answers here:
How do I pass variables and data from PHP to JavaScript?
(19 answers)
Closed 6 years ago.
I have three files a .php, a .html and a .js. How can I combine all three of them so that I can use the value of a variable set in php in JavaScript?
I will have to save this file by .php extenstion
<html>
<head> </head>
<body>
<?php
// here I can write my php code ?> // I can end it any time to include some JS code here
<script> Some js code</script>
<?php // and start again to write some more php code
?>
</body>
</html>

How to find jquery or javascript event occure from which file? [duplicate]

This question already has answers here:
Find jQuery code that trigger then event in Web Browser
(2 answers)
Closed 8 years ago.
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/file1.js"></script>
<script type="text/javascript" src="http://code.jquery.com/file2.js"></script>
<script type="text/javascript" src="http://code.jquery.com/file3.js"></script>
<script type="text/javascript" src="http://code.jquery.com/file4.js"></script><script type="text/javascript" src="http://code.jquery.com/file5.js"></script>
i have 100 or more js file alert message comes from anywhere how can i hide and find ?
I think a direct method is not available. A possible way is to use inspection tools or any event
visualization plugins.
In your case you can use current page name on alert messages to identify the pages.
var script_name = document.getElementsByTagName("script")[0].src;
alert( 'alert message from the file ' + script_name );
But i dont think its a good way. I suggest to use tools like visual event
http://www.sprymedia.co.uk/article/Visual+Event+2
google chrome plugin is also available
http://tinyurl.com/a5hcod2
lets say you have this
File 1:
$(element).bind("click", function(){
console.dir('button in some file', this);
});
File 2 :
$(element).bind("click", function(){
console.dir('button in another file', this);
});
if you click and check your console you should have something like this
button in some file html elememt .... file1.js:15
button in another file html elememt .... file2.js:20

Categories