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');
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 1 year ago.
Improve this question
I apologize for the lack of code on this one. I am totally lost on a starting point.
On a website there is a link such as the following:
This Is My Link
I am trying to get the accountId of 00T122233ABCEFG123 and use it as a variable. The link that appears above does not have an id, so there is no way to target it other than to find "accountId" on the page, as it only appears in the page once.
Any help is greatly appreciated.
You could use a selector to target the element based on the href attribute, and then extract the value through the URL api
const link = document.querySelector('a[href*="accountId"]');
const href = new URL(link.href);
const id = href.searchParams.get('accountId');
console.log(id);
This Is My Link
You can select it using the attribute contains selector :
a[href*=accountId]
Otherwise, maybe its parent has an ID? There are many ways to target an element in a page.
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 5 years ago.
Improve this question
I'm trying to create a navigation menu using jQuery with links to each <h2> title on pages created and published in Wordpress. Some of these pages can get a bit lengthy so this navigation menu should make it quick and easy for visitors to jump to certain parts of it's content.
I've got it set up so that each <h2> title creates it's own unique ID by using it's content prefixed by "#" (i.e. "My title" would get the ID "#My title") using this piece of code below:
jQuery("h2").each(function(){
var id = jQuery(this).html();
jQuery(this).attr("id", "#" + id);
})
Basically step 1 of 10.. What's left is to create a function that loops trough each <h2> that exists on the page and then creates a menu item for each of those titles. I kind of understand javascript loops but I'm just not sure how to get this to actually create new elements like this.
I'm still a novice when it comes down to Javascript or even jQuery so I apologise if anything's unclear.
Anyways I hope somebody can point me in the right direction. Any help would be much appreciated.
From what I understand, I'm guessing that you are trying to create a navigation menu at the top of the page where it creates links to each of your <h2> subheadings.
I don't really know how wordpress works but here are some ways that it can be achieved in jquery:
You should store your <h2> elements in an array. You can do this by adding the id as you make them. You don't need a loop for this! (Also, if I were you, I wouldn't add the # before the ID, because then you would have to write "##name" when you try to call the ID in javascript or css.)
var arr = [];
$("h2").each(function(){
var id = $(this).html();
$(this).attr("id", id);
arr.push($(this).attr('id'));
});
Now that you have the data for your <h2> elements, you can just loop through it to create your list. First, just create an empty <ul id="nav"></ul> in javascript. Then, you can keep adding <li></li> in it with the h2 contents. To add the links, you just have to surround the text with an <a href='#name'></a>.
So it would turn out to be something like this:
for (i in arr) {
$('ul#nav').append('<li>' + arr[i] + '</li>');
}
You can of course then make the css to style the unordered list, and it can serve as a nav.
I hope that helps!
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>
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 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 years ago.
Improve this question
Is there a possibility of "linking" two CSS elements in jQuery?
An example from my project:
I'd like to append a .focused class to multiple elements at once when certain things happen. They all have the same prefix in their ID, but there is >1 of those prefixes (like #first-header - #first-button ; #second-header - #second-button and so on). It would probably use some regular expressions, but I can't seem to figure this stuff out.
A more accurate example, because I'm bad at explaining things:
When #first-header is .focused, append the same .focused class to #first-button as well. And that would need to work to any pair of -header and -button.
I hope I explained it well enough and am thankful for any kind of help.
You can easily select all items whose id starts with first- like this
$('[id^="first-"]').addClass('whatever');
It sounds like instead of using patterns in the ID of your HTML elements you should be using classes.
Example HTML:
<div id="first-button" class="button">...</div>
<div id="second-button" class="button">///</div>
Javascript:
$(".button").click(function(){ /*do stuff*/});
That Javascript would attach a click handler to all div elements with the class button.
$('[id$="header"]').on('focus blur', function(e) {
$('#' + this.id.split('-').shift() + '-button').toggleClass('focused', e.type=='focus');
});
FIDDLE
You cannot have multiple ids for one element. The proper way to do what you're doing is to give everything that you want to change a class like "toFocus"
Try this:
$("[name$='header']").focus(function(){
var t = $(this).attr("id").split("-")[0];
$("#"+t+"-button").addClass("focus");
});