Adding an id on to a href jquery [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to get the id of an radiobutton to be added to href when the link is clicked. I tried searching google for a long time. But maybe i'm missing because it's very basic.
I do have a bit of code written but it doesn't work. Help?
function ProductIDLink() {
var url = "/bbbb/aaaaaaa/" + ('.aaasaff:radio:checked').attr('id');
$("#safad").attr("href", url)
}

Looks like you've just forgotten a $:
... ('.aaasaff:radio:checked').attr('id')
should be
... $('.aaasaff:radio:checked').attr('id')

From what I can see the $ was missing.
function ProductIDLink() {
var url = "/bbbb/aaaaaaa/" + $('.aaasaff:radio:checked').attr('id');
$("#safad").attr("href", url)
}

Related

Improving code for learning purposes [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have three tabs and I want to navigate when I click on each one of them. The code that I wrote is working just fine, but I believe that is bad coding, there is any way to improve this is just for learning purposes. Thanks!!!!
jQuery(".nuestra_actualidad li:eq(0)").click(function() {
jQuery("#tabs-actualidad").css("display","block");
jQuery("#tabs-articulos").css("display","none");
jQuery("#tabs-noticias").css("display","none");
});
jQuery(".nuestra_actualidad li:eq(1)").click(function() {
jQuery("#tabs-actualidad").css("display","none");
jQuery("#tabs-articulos").css("display","block");
jQuery("#tabs-noticias").css("display","none");
});
jQuery(".nuestra_actualidad li:eq(2)").click(function() {
jQuery("#tabs-actualidad").css("display","none");
jQuery("#tabs-articulos").css("display","none");
jQuery("#tabs-noticias").css("display","block");
});
Replacing jQuery with $ if possible (unless it clashes with another library) and then it can be reduced to a single function by utilising the index of the clicked element and calling the toggle function:
$(".nuestra_actualidad li").click(function() {
var index = $(this).index();
$("#tabs-actualidad").toggle(index === 0);
$("#tabs-articulos").toggle(index === 1);
$("#tabs-noticias").toggle(index === 2);
});
Example - http://jsfiddle.net/gSKeL/

How can I convert this coffeescript to js/jquery? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
text = child.html()
text = text.replace /(#include(\s*<.*>)?)/gi, '<span>$1</span>'
text = text.replace /(main\(.*\))/gi, '<span>$1</span>'
child.html text
http://jsfiddle.net/dcro/XKHC8/
This is an answer from my question: Wrapping strings with a span I dont know how to use coffeescript and the one who answer looks unavailable.
From js2coffee.org
var text;
text = text.replace(/(#include(\s*<.*>)?)/gi, '<span>$1</span>');
text = text.replace(/(main\(.*\))/gi, '<span>$1</span>');
child.html(text);

How to replace occurrences by key [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
This is a simple question about JavaScript,
Say I got the following string:
A)My Name B)My Name C)My Name
now I give to a function the key #1 expecting to replace the second occurrence of My Name inside that function and return:
A)My Name B) C)My Name
I haven't found the solution to this anywhere online so I'm asking.
You could use split to separate the string into the parts, then join the before and after back together:
function removeNthMatch(input, removeString, removeIndex) {
var splitString = input.split(removeString);
result = splitString.slice(0, removeIndex + 1).join(removeString)
+ splitString.slice(removeIndex + 1).join(removeString);
}
input = "A)My Name B)My Name C)My Name";
removeString = "My Name";
removeIndex = 1;
console.log(removeNthMatch(input, removeString, removeIndex));

JavaScript concatenate a variable into a constructor [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am trying to concatenate a variable into a constructor in JavaScript
I have a variable like this:
var selectedLayer = "myLayer";
and then I am creating a Leaflet tile layer, I want to then incorporate the variable into the constructor:
test = new L.TileLayer.WMS('http://localhost/geoserver/wms',{layers : 'geonode:<selectedLayer>', format: 'image/png'});
string concatenation in javascript is done with the simple +, so your case would be:
{
layers: 'geonode:' + selectedLayer,
format: 'image/png'
}

check if url is a root url [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm looking for a regex to test if a url is a root url:
http://site.org TRUE
http://www.example.com TRUE
...
http://www.example.com/dir FALSE
http://www.example.com/image.jpg FALSE
http://www.example.com/dir/file.doc FALSE
Try below regex will do the work
/^https?\:\/\/[^\/]+\/?$/
I tested like this:
var URL = "http://jsfiddle.net/";
var check =/^https?\:\/\/[^\/]+\/?$/.test(URL);
alert(check);
JSFiddle
try this:
var str='url...';
if(str.indexOf("/")<str.indexOf(".")&&(str.indexOf("http://")>-1))
return true;
else
return fals;
Try out with this regular expression
(?\w+)://(?[\w#][\w.:#]+)/?[\w.?=%&=-#/$,]*

Categories

Resources