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 hard time try to kill all facebook features don't like, don't want, don't vereryting.
So i try using gresemonkey to do it, but so far i can't make it work every time i try, fail when i use get document id lets say "content" works fine buy when i try thinks like "fb-Like" don't do anything . there is what i have so far. i hope us can put me in then right way.
//this part becouse come fb-likes are like class and no have id
var killerface = document.getElementsByClassName("like-box");
for (var i = 0; i < killerface.length; i++) {
killerface[i].setAttribute("id","like-box");
}
this should be remove the child, but it's not...
var killerface2 = document.getElementById("like-box");
killerface2.parentNode.removeChild(killerface2);
have any ideas?
the idea is clean clear remove all pages using greasemonkey from facebook, google plus,any other that follows also some ads and everything dont like you. the idea is not only hide.
Add this in your HTML before last tag. (Need you have a jquery)
<style>
.deadface { display:none !important; }
</style>
<script>
$(function() {
$('.like-box').addClass('deadface');
});
</script>
Or this to completely remove
<script>
$(function() {
$('div.like-box').remove();
});
</script>
Related
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 6 years ago.
Improve this question
I want to disable a href tag when the link of it is # , the reason i want to do this is because i have lots of post on my webpage that have links poiting to other sites that are my partners.
When i make a post i have a template that make it easier on me to put information on it and have the href link ready if anyone site that has to do with the post want a partnership and i link it to them .
Some of my old post have href tags with # value on it and when i click on them they open up my page on another tab so thats why i would like to disable it if possible with javascript (anyone other script language that can do the job is fine too)
Thanks
Simplest way would be:
var emptyAnchors = document.querySelectorAll('a[href="#"]');
for (var i = 0; i < emptyAnchors.length; i++) {
emptyAnchors[i].addEventListener('click', preventDefaultEvent);
}
function preventDefaultEvent(e) {
e.preventDefault();
}
This will prevent the default behavior on a link click (open the href target).
You can select your a tag with the specific # href
ES6 syntax
const elements = document.getElementsByTagName("a[href='#']");
ES5 syntax
var elements = document.getElementsByTagName("a[href='#']");
then add a preventDefault() on the event of each element to make sure the default behaviour won't be executed.
ES6 syntax
elements.addEventListener('click', e => {
e.preventDefault();
});
ES5 syntax
elements.addEventListener('click', function(e){
e.preventDefault();
});
If you want you can just add css to make the a tag lose its default style
a[href="#"] {
color: black;
pointer-events: none;
text-decoration: none;
}
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 8 years ago.
Improve this question
I have an a tag inside of a form that is used to remove uploaded files. I don't want the a tag to take the user to another section of the page, or try to submit the form or anything like that, I only want it to run a javascript function. How can I accomplish this? I'm not sure what to put in the href?
You can use #:
function doSomething() {
alert('test');
}
Click me
Really, any URL can go there - the return false; short-circuits the default behaviour of the link.
In general, if at all possible, it's best to use a real URL that does the same thing your JS does, for users who have JS disable. This is called "graceful degradation".
You really need to add more code and examples to your questions in the future. Fortunately I know what you're actually asking.
In the function that runs when you click the link, you want to prevent its default behavior.
Here's a very simple example:
<a href="http://google.com" id="myanchor">
Javascript
document.querySelector('#myanchor').addEventListener('click', function (ev) {
ev.preventDefault();
// your code here.
});
<form>
<!-- other inputs-->
<input type='button' onclick='run()' />
</form>
Then for the Javascript:
function run() {
//do something
}
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 8 years ago.
Improve this question
Let’s say I’ve put, somewhere on the internet, a link to my website. To be specific, it was a URL with an anchor/hash linking to a part of an article, like this: http://example.com/article/#subsection.
Now, if someone came through this link to my website, how can I trigger CSS/JS to make some action?
In my particular case, I want to add a style to the <div> with an id of subsection when someone uses the link containing #subsection.
Any ideas?
Given IE9 and later, this is possible entirely through the :target pseudo-class:
#subsection:target {
…
}
If what you're trying to do is to highlight a section on your page that matches the hash value in the current URL (which isn't entirely clear from the wording in your question) and you want to support a wide range of older browsers, then you can do something like this:
The hash value is not sent to the server so you would have to apply a change in client-side javascript. You can do that by adding a class to the object that matches the hash name when your page loads:
<script>
var id = window.location.hash.slice(1);
if (id) {
var obj = document.getElementById(id);
if (obj) {
obj.className += " specialStyle";
}
}
</script>
Or, using jQuery:
<script>
if (window.location.hash.length > 1) {
$(window.location.hash).addClass("specialStyle");
}
</script>
These scripts must be located anywhere after the elements you wish to add the class to or protected from executing until the DOM is loaded using something like $(document).ready(), though the sooner the script can run, the sooner the new style will show.
It's unclear to me whether the XSS vulnerability mentioned in the comments is still an issue in jQuery now or not, but you could either using the plain javascript version (which does not contain this vulnerability) or further protect against that in the jQuery version with something like this:
<script>
if (window.location.hash.length > 1) {
$(window.location.hash.replace(/[<>]/g, "")).addClass("specialStyle");
}
</script>
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Often while coding and debugging I might want to comment out a <script> tag. An example might be when doing the following:
<script src="lib/jquery.js"></script>
<!--script src="lib/jquery.min.js"></script-->
I tend to add the new line instead of just changing the original to act as a reminder that I want to put that back before going live. I got this syntax from a colleague but I had never seen this it before. Is there a syntactically correct method to comment out <script> tags in HTML?
EDIT: I know there are lots of discussions about commenting out scripts in order to hide them from older browsers but that is not what I am doing. I am wanting to hide the tag completely.
One option would be to dynamically load your scripts in, given a debug flag. For example:
Markup:
<script src="lib/include.js"></script>
include.js
var IS_DEBUG = true;
if(IS_DEBUG) {
loadScript("jquery.js");
loadScript("anotherscript.js");
}
else {
loadScript("jquery.min.js");
loadScript("anotherscript.min.js");
}
function loadScript(name) {
var elem = document.createElement("script");
elem.src = name;
document.getElementsByTagName("head")[0].appendChild(elem);
}
That means you can just toggle the IS_DEBUG flag to load in the required scripts. This is a very rudimentary example, but you get the idea. You might even be able to tie this in with something like require.js
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
Hello i have been trying to make a dynamic collection that i can post to the server, after some struggeling i found this guide;
http://jarrettmeyer.com/post/2995732471/nested-collection-models-in-asp-net-mvc-3
Great written but i havent got it to work for my needs.
Everything works fine exept one "little" annoying thing.
First some information about what im trying to achive;
My classes looks like this;
Qpack has a list of questions
question has a list alternatives
The interface that i have created looks like this;
And this is the markup.
The "add Question"-button works great and the markup match, The thing that dosent work is that wen i click on "Add Alternative" it is always being added to the first question. But the markup is fine as seen in the second picture.
The function responsible for the append looks like this;
function addNestedForm(container, counter, ticks, content) {
var nextIndex = $(container + " " + counter).length;
//var nextIndex = $(counter).length; // Orginal
var pattern = new RegExp(ticks, "gi");
content = content.replace(pattern, nextIndex);
$(container).append(content);
resetValidation();
}
I want to append to the most relative "alternatives" but it seems that it always goes for the first, any idea how to get it to understand the "nearest" alternatives?
When a jQuery selector specifies an ID (#) and there are multiple IDs in the Html document that have that Id jQuery will always return the first.
You must have a way to specify the "Alternatives" uniquely throughout your page.
Alternatively (pun intended) you can create a new css class, replace
<div id="alternative" ...
with
<div class="alternative-container" ...
Then on your action of "Add Alternative" you can
var container = $(this).parents('div.alternative-container:first');