how to pick value in jquery [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i have build a small function whose work to get value in alert box but i want to pick only 5 character from starting. here is my function
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
$(function (){
$(".hhh").click(function(){
$(this).html()
})
})
</script>
</head>
<body>
<div class="hhh">dd:ff:aa</div>
</body>
</html>

You could use the substring method:
$('.hhh').click(function() {
alert($(this).html().substring(0, 5));
});
Obviously checking the length of the string before calling substring to ensure that it has at least 5 characters could be a good check to do.

Do you mean substr ?
$(this).html().substr(0, 5);

Related

How to use localstorage data in the body of an HTML 5 website [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 days ago.
Improve this question
How do I call the localStorage variables into the body of the website? Each variable will go under the matching tag. The code I am working on is below.
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script language="javascript"></script>
</head>
<body>
<h2>Homemade Beer</h2>
The production time is:
<h2>Homemade Cider</h2>
<h2>Moonshine</h2>
<h2>Homemade Wine</h2>
<script>
localStorage.setItem("MoonShineProductionTime", "4");
localStorage.setItem("AppleCiderProductionTime", "5");
localStorage.setItem("HomemadeBeerProductionTime", "4");
localStorage.setItem("HomemadeWineProductionTime", "7");
</script>
'
I tried:
Homemade Beer
The production time is: JSON.parse(window.localStorage.getItem('HomemadeBeerProductionTime'));
The lined was shown on the web browser with no stored value.

JavaScript Onclick Function Fails to Execute [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 months ago.
Improve this question
I have a button that triggers an onclick function:
<!DOCTYPE html>
<body>
<h2>what can javascript do?</h2>
<p Id="demo"></p>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
<button type="button" onclick='document.getElementById("demo").innerHTML = "Hello Javascript!"'>Click Me!</button>
</script>
</body>
</html>
when clicking the button, I found that the onclick does not trigger. What might be the problem with my code?
You don't need jQuery
Use addEventListener instead and set an ID to your button Element
use textContent (instead of innerHTML)
Add the missing <html> tags etc
Use type="button" on a Button Element (since by default is of type "submit")
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Demo</title>
</head>
<body>
<h2>what can javascript do?</h2>
<button type="button" id="demoButton">Click Me!</button>
<p id="demo"></p>
<script>
const elDemo = document.querySelector("#demo");
const elButton = document.querySelector("#demoButton");
elButton.addEventListener("click", () => {
elDemo.textContent = "Hello Javascript!"
});
</script>
</body>
</html>

select all text in JavaScript [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
i need to select all text in my html code and surround them with <span> tag in JavaScript
convert this code:
<!DOCTYPE html>
<html>
<body>
<h1>Heading</h1>
<p>paragraph.</p>
</body>
</html>
to this:
<!DOCTYPE html>
<html>
<body>
<h1><span id="text">Heading</span></h1>
<p><span id="text">paragraph.</span></p>
</body>
</html>
how can i do this?
You can wrap your text with this fonction :
$(selector).wrapInner( "<span class=\"text\"></div>");
where selector target the tag you want
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(document).ready(function(e) {
$('html').prependTo('<script>');
});
</script>
</head>
<body>
hi
</body>
</html>

Mozilla Firefox bug or ..? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I wrote the code and saw a bug in firefox and little bug in chrome
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mozila Firefox</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$(function(){
$(window).scroll(function(){
if ($(window).scrollTop() == $(document).height() - $(window).height()){
alert('1');
}
});
});
</script>
</head>
<body>
CONTENT FOR SCROLL
</body>
</html>
When I scroll this page in firefox i getting bug which covers the black transparent background browser.
In chrome just more and more alerts.
Close your tabs in firefox!
Live: http://forum.xeksec.com/habr/mozilla_crash_or_wtf/
See https://bugzilla.mozilla.org/show_bug.cgi?id=723532
Edit :
The above doesn't always work... In fact, I've checked some solutions around, including here in Stack Overflow. What other usually advice have the same problem (eg Alert using Jquery when Scroll to end of Page)
I'm using FF11 on Ubuntu.
I think this was a performance issue. If you put your maxScroll in a variable it works (at least for me)
Here's my code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mozila Firefox</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$(function(){
var maxScroll = $(document).height() - $(window).height();
$(window).scroll(function(){
if ($(window).scrollTop() == maxScroll){
alert('1');
}
});
});
</script>
</head>
<body>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
</body>
</html>

How can I detect browser support of Flash in JavaScript? [duplicate]

This question already has answers here:
Closed 11 years ago.
This my HTML code but if the browser does not support Flash then I want to replace the image in the Flash part
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
if (typeof navigator.plugins['Shockwave Flash'] !== 'undefined') {
alert('support');
} else {
alert('not support');
}
</script>
</head>
<body>
</body>
</html>
I would use one of the Flash Detection JavaScript libraries out there. This one works well.

Categories