I'm trying to create a piece of code that will check a webpage and replace any instances of a specific line of HTML with another line of HTML. The code I have so far doesn't work, but I have a feeling that's down to my awful Javascript skills! For example, in the following code I'd want to replace all instances of
<li><a href="index.pdf">Index</a></li> with <li><a href="contents.pdf">Contents</a></li>
The Javascript I have so far is:
<script type="text/javascript">
var aEls = document.getElementsByTagName('a');
for (var i = 0, aEl; aEl = aEls[i]; i++) {
aEl.href = aEl.href.replace('index.pdf','contents.pdf');
}
Obviously this is meant to just replaces the a href elements, but I got a bit stuck after this!
where the selectors and their opening braces, their closing braces, and declarations are each on their own lines (always), how can I replace a specific declaration (line) given a unique selector and a declaration property. For example, if I wanted the 'color' declaration property line in the 'bar' class changed.
At the moment I'm iterating through the CSS one line at a time looking for the selector and then looking for the declaration property (before I hit the closing brace).
I have this page created, And in the page is a news header, In the header it says %ss%. Can someone help me create code, so that in the footer of the page javascript finds this %ss% and replaces it with text from a webpage?Code:What the web page that needs inserting does:I have this game and it uses php fsockopen to determine if a port is open. If the port is in use the page displaysThe server is <font color="#0066FF"><b>Online!</b></font>Otherwise it's:The server is <font color="#FF0000"><b>Offline!</b></font>
I can't seem to find what I need but I know it exists. I trying to find a vertical scroller that will automatically have the text scroll upwards but have an arrow above and arrow below to be able to control the direction of the scrolling text, or a script with no arrows but still allow me to take control by mousing over the text to scroll up or down.
I'm having an issue with doing a simple js task. I have a list of hyperlinks that contain various paths. For instance: a href="[URL] a href="[URL]
What I need is to remove the term "content" from all the hyperlinks in it's contain div. There is got to be a simple way of doing this and I can't seem to find the right direction. I also need to have the targets changed as well, which I was able to complete. window.onload = function(){
var anchors = document.getElementById('containerDiv').getElementsByTagName('a'); var links = "content"; for (var i=0; i<anchors.length; i++){ anchors[i].setAttribute('target', '_blank'); } }
I have following jquery, which clicking a anchor link to load a content and replace the h1 to h2 tag in the loaded content before replacing a div content on current page. $('.previous-news li a').click(function() { var url = $(this).attr('href'); var link = this; $('.attachment-content').fadeOut("slow"); $.get(url, function(data) { var $fullcontent = $('#main-content', data); var html = $fullcontent.html().replace(/h1/g,"h2"); $(link).parents('.view-content').parents('.view-dom-id-2').find('.attachment .attachment-content').html(html); }); $('.attachment-content').fadeIn("slow"); return false; }); It works on firefox and webkit browsers but not in IE8 or 7. H1 tag is not replaced.
I am wanting to select a set piece of html and and replace it with another piece of html.I've used the replaceWith command but I don't think I've written the script correctly to select the piece of html as it breaks the script.
I have a problem with html select. i will be selecting an element from the select drop down, then i will click a button which will result in changing the position of this element with the element just above it. Is it possible, I am getting the element id, I thought of using replaceWith method, but its giving some error. "uncaught exception: Syntax error, unrecognized expression: # ". I also wanted to know if this thing is possible in jquery or not..
Is there a possibility to find out the coordinates, relative to the whole screen, or at least relative to the browsewindow, where an element ( e.g. link or picture ) begins or ends?
I'm building a JavaScript-based calendar for a client that will require me to replace the page's HTML based on the user's input. For example, if the user clicks on a particular date, then the month/week calendar will be replaced with the day calendar. Needless to say, there are several event listeners involved. However, if I suddenly swap out the month calendar for a day calendar, does that mean that there are several event listeners in memory for elements that no longer exist? Or are those listeners destroyed when the elements are destroyed? Basically my question is, every time I swap out the HTML, do I have to detach all of the old events too?
Basically what I need to do is cause a bit of HTML to only display on a specific page. I have figured out how to do most of the work i.e. figuring out what page that the code is being displayed on, etc. However, for some reason the DOM element that I am using will not update based on the Javascript.
Here is the version of the code that I am currently working on: <html> <head> <script type="text/javascript"> window.onload = function DisplayButton() { var DesiredPage = 'Page to Display'; //Page that I want the code to display on var sPath = window.location.pathname; var sPage = sPath.substring(sPath.lastIndexOf('/') + 1); //This determines and places in a variable what page that the code will be on if (sPage == DesiredPage) { document.getElementById('HiddenCode').style.display = "block"; }} </script> <p Id="HiddenCode" style="display:none">Code only to be displayed on indicated page</p> </head> </html>
I need some help creating some regular expressions that remove specific html tags...the script/expression will run when a button is clicked (i.e. "Remove Bold" button will remove <b> </b>).
currently I have these expressions working but they do not accomplish what exactly what I am after...Actually the functionality I'm looking for will incorperate both, however I can't seem to get it to work properly...
data.replace(/<[^>]+>/ig,"")+""); - this removes all tags (no matter what kind), I would like it to be a little less "greedy" and only remove specific tags. i.e: Input = <u><b>THIS IS SOME DATA</b></u> Output= THIS IS SOME DATA
data.replace(/<(B|b)[^>]*>[^<]*(</B>|</b>)/ig,"")+""); - this removes bold tags and will leave other tags like <u> behind, exactly what I was looking for. However, it also removes the content/data that is wrapped in the tag. i.e: Input = <u><b>THIS IS SOME DATA</b></u> Output= <u></u>
In the above example what I would like to happen is: Input = <b><u>THIS IS SOME DATA</u></b> Output= <u>THIS IS SOME DATA</u>
Well after much trial and error I come asking for help. I am trying to write a greasemonkey script that scans a page for all the values between certain <td> tags. When I used firebug it shows what I am looking for as <td class="username">THEUSERNAME</td> but when I view the source it just shows up as <td>THEUSERNAME</td> I want to create an array of the 100 <td>'s on the page that pertain to usernames but none of the other <td>'s
I created a test page that mimicked the code, what I thought origionally, to be so I could test my script with ease. And it worked when there was an actually <td class="username">
This is what I have so far:
// ==UserScript== // //Displayable Name of your script // @name EXAMPLE
I am trying to do is load new content into a form without resetting the form. I have about 10 checkboxes, once 4 are selected I would like to reload a div in the page to insert four corresponding textareas with the same id as the checkboxes. So for example the checkboxes:
There would be about 10 after 4 are selected than four divs with textareas are loaded onto the page - These textareas have the same id in order for the right ones to load. If your wondering why not just hide the textareas and show when then have been selected by the checkboxes, its because they have a wysiwyg editor attach so it would start to load slow after I add say 10-20 different textareas.
Would this work: Code: $(document).ready(function() { $('#reload_1').click(function() { //var names = []; var myScripts = new Array(4) $('#page_select input:checked').each(function() { names.push(this).attr("id"); }); $('#content_div').load('external_content.php.html # . + '. myScripts[0]); $('#content_div').load('external_content.php.html # . + '. myScripts[1]); $('#content_div').load('external_content.php.html # . + '. myScripts[2]); $('#content_div').load('external_content.php.html # . + '. myScripts[3]); If I had all the divs and textareas in external_page.php and load only the ones needed.
I wanted to know how can I check for a specific HTML tag or user defined TEXT and delete it when the page loads
Whenver the IE loads the page my company add its COMPANY NAME in my office on any page so what I want to do is to check for my company name b4 the page loads and remove the company name and then load the page.
How can I use jquery to cycle through all the table rows I have in a table, and hide the rows that contain a specific HTML value that I pass to jquery?For instance, I have a table full of students, and courses each student is taking. If I want to hide all the rows where the course is Chemistry (regardless of student), how would I do that?I already have captured the HTML value, what I mainly need help with is how to tell jquery to hide ALL of the rows with that HTML value, rather than just the row I click on.
I've got some text that I want to change what it says:(63%) on RRP (£80.00) The percentage value and RRP Price will change dependant on the product and its discount. All I want to change with jquery is the text:
What is happening is $(this) is no longer based on .expand being the (this) that is clicked.
like if i have a button SOMEWHERE randomly on the page with this
<div onclick="Minimize('_alerts');">Click Here</div> this will minimize alerts but because the (this) in minimize function doesn't actually point to the right button that I want to add a class to.
Is there a way to modify the minimize function so that it finds the <div id="mytoggle"><ul> <li class="expand boxminimize" rel="_alerts"> using the rel toggle, and then changes the class of the li from expand boxminimize to boxexpanded??
just like the .expand click function I posted on the top of the post that works?
Another thing that has been driving me crazy is that css positioning is handled differently by different browsers. JS is not my area, but I can do a lot with CSS, and I do, but cross browser compatibility is killing me.
I can use an IF IE statement and only IE runs that segment of code, but I haven't been able to figure out out how to make ONLY firefox or ONLY opera or safari enact an encapsulated segment of code. The same type of IF statement doesn't work for them.
Is there a single method using JS that works for all browsers?
function result(){ var result = document.getElementById('resss').innerHTML; }
But what I actually want is to import data from a table of an external website. E.g. I want to get the innerHTML of a specific cell in column 3 and row 2 of a specific site.
I have a script which gathers information from a form and, if needed, writes this info to a 'preview' window. At times {tokens} are used in place of real html tags. How can I tell the script to look for "{" and "}" and replace them, respectively, with "<" and ">".
I tried using "str = str.replace(/{/g, "<").replace(/}/g, ">");" but that didn't work. The script in question is being written by PHP... thus, may be generating a syntax-based failure. Any ideas?