I'm trying to make a text into a link in my Javascript code. This should work but it doesn't.
var strLink = "mysite.com" ;
var cb_header = chatbox.find('.imjs-header');
cb_header.html(cb_header.html().replace('{username}', strLink));
I have a variable called username and it is a string. That is the string that used to replace {username}. Maybe I can use jquery? I can't seem to get it a link though. Any pointers in the right direction are greatly appreciated.
Thank you,
Arjun
var strLink = '"mysite.com" ';
Try this:
var strLink = '"mysite.com" ';
Related
I am trying
function ddtip(thetest, thetext)
var Test = document.all[thetest].innerHTML;
var str = document.all[thetext].value;
var MyArray = str.split(",");
but it is not working in Firefox but the same is working in IE. thetest and thetext are the ID of the Server Controls.
I also tried with document.getElementById[thetest].innerHTML; but it is throwing error.
Please Help.
Thanks,
Rahul
If "thetest" is a variable then getElementById should work. If it is the id of the element you are looking for then it should be like this: document.getElementById('thetest')
I'm trying to achieve something that 'should' be fairly straightforward, bit I can't find anything online to help me out.
I have some CSS class names that are being output with ampersands in them (its down to the system I'm using and is unavoidable). I'd like to use a little bit of jQuery to simply remove the ampersand, so a string that looks like:
class="Middle&East"
would be
class="MiddleEast"
Any help with this would be very much appreciated.
Thanks
To replace them all you could;
$('[class*=\\&]').each(function() {
$(this)[0].className = $(this)[0].className.replace(/&/g,"");
})
Try:
var class="Middle&East"
class.replace('&', '');
You will have to escape the & if you are using jquery
Try
$(".Middle\\&East").removeClass("Middle&East").addClass("MiddleEast");
DEMO
General solution to remove & from classname
$(function(){
$('[class*="&"]').each(function(){
var $this = $(this),cname = $this.attr('class').replace(/&/g,'');
$this.attr('class',cname)
})
})
Maybe something along
$(".Middle&East").removeClass("Middle&East").addClass("MiddleEast");
This one seems to works for me :
$(function() {
$('[class="Middle&East"]').toggleClass('Middle&East MiddleEast');
});
Here's a jsfiddle : http://jsfiddle.net/U3r7G/
var className = $(element).attr('class');
var modifiedClass = className.replace('&', '');
$(element).attr('class', modifiedClass);
I am dumping some CSS into a div and I am looking to format it so it is more legible. Basically what I want to do is insert a break tag after every semicolon. I have searched around for a while but can't seem to find something that quite fits what I am trying to do.
I have something like this...
HTML
<div class='test'>
color:red;background-color:black;
</div>
jQuery
var test = $('.test').text();
var result = test.match(/;/g);
alert(result);
And I have tried..
var test = $('.test').text();
var result = test.match(/;/g);
result.each(function(){
$('<br/>').insertAfter(';');
});
alert(result);
Also I have started a fiddle here.. Which basically just returns the matched character...
http://jsfiddle.net/krishollenbeck/zW3mj/9/
That is the only part I have been able to get to work so far.
I feel like I am sort of heading down the right path with this but I know it isn't right because it errors out. I am thinking there is a way to insert a break tag after each matched element, but I am not really sure how to get there. Any help is much appreciated. Thanks...
try it like this
var test = $('.test').text();
var result = test.replace(/\;/g,';<br/>');
$('.test').html(result);
http://jsfiddle.net/Sg5BB/
You can use a normal javascript .replace() method this way:
$(document).ready(function(){
$(".test").html($(".test").html().replace(/;/g, ";<br />"));
});
Fiddle: http://jsfiddle.net/SPBTp/4/
Use This CODE
var test = $('.test').text();
var result = test.split(';').join(';<br />')
http://jsfiddle.net/FmBpF/
You can't use jQuery selectors on text, it only works on elements.
Get the text, just replace each ; with ;<br/>, and put it back.
$('.test').html($('.test').text().replace(/;/g, ';<br/>'));
Try something like this :
var test = $('.test').text();
var result = test.replace(/;/g,";");
$('.test').html(result);
That should work if you stick it into your jfiddle.
I have two text fields in an html form with id 'co_addrcheck' and 'usrad_co_addr'. I tried concatenating the two values and copy that to another text field. I tried using the following code but the new text has an 'undefined' value.
var loc = document.getElementById('co_addrcheck');
var home = document.getElementById('usrad_co_addr');
Neither
var post2 = loc + home;
nor
var post2 = loc.value + home.value;
works.
Any help would be highly appreciated.
Assuming they're text inputs, you should use the "value" property,
var post2 = loc.value + home.value;
I hope it helps
Second one should be working. And best advice is to enclose within try/catch and see the error message.
I'm attempting to create a div tag and then alter it via css, but for some reason its not working here's my code:
$('#draw').click(function(e){
var divToAdd = "<div id='box' style='display:block;background-color:red;width:100px;height:100px'></div>";
$("#area").append(divToAdd);
});
$('#left').click(function(e){
//var leftNow = document.getElementById("box").left + 1;
alert(document.getElementById("box").left);
$("#box").css('left',leftNow);
});
$('#right').click(function(e){
var leftNow = document.getElementById("box").left - 1;
$("#box").css("left","90");
});
So for some reason the value of document.getElementById("box").left is undefined. I've been trying to figure this out for a while, i've probably got something wrong in my syntax perhaps? Any help would be appreciated, thanks alot! Thank you Nick Craver.
You would need .style.left, or $("#box").css('left'); in this case.
But...there's an easier way, like this:
$("#box").css("left","-=1");
You can just make it relative this way, same for +=, keep it simple :)
Here I have two suggestions:
(1)Use jQuery object instead of object itself
var divToAdd = $("<div id='box' style='display:block;background-color:red;width:100px;height:100px'></div>");
Actually the expression above is not so good either, to make it more 'jQuery":
var divToAdd = $('<div></div>').css('background-color','red').css....
(2) Keep using jQuery if you involved it
$('#box').css('left') instead of document.getElemengById(...)