add a group of links in html - html

i have a word file with 100 different hyperlinks.
Eg:
http://word1.com
http://word2.com
upto http://wordn.com
I have to create a html file with these n links.
like word1 which has a hyperlink to word1.com, word2 which has a hyperlink to word2.com etc
Any easy way to do this? rather than copy pasting the link and writing the code?

You could use a JavaScript loop to do this. Such as the for loop:
for (var i=0;i<100;i++)
{
document.write('Word' + i + '');
}
like so...
I don't know if this is what you're looking for, but i hope I helped!

You can use a simple loop and create an anchor in each run. Use the .setAttribute("href", "word"+count+".com") where count keeps incrementing, using Javascript. See fiddle

Related

Display value + text using jQuery

I am a total beginner. I have a form in HTML and am trying to calculate a specific value using jQuery. I want this value to be displayed in paragraph <p id="final"></p> under the submit button, but am actually not sure, why my code isn't working.
jQuery(document).on("ready", function() {
jQuery("final").hide();
jQuery("#form").submit(function(e){
e.preventDefault();
const data = jQuery(this).serializeArray();
/*
some calculations
*/
$('#final').html($('#final').html().replace('','result + " text"'));
jQuery("#final").show();
}
}
Do you have any idea, what could I be doing wrong??
You've got a several issues here.
Firstly, don't mix jQuery and $. If you're using the former, it's normally to avoid jQuery's alias, $, from conflicting with other code that might use $.
Secondly, you don't actually do any calculation (from what I can see in your code), so I'm not sure what you're wanting to output. I'll assume you're going to fill that in later.
Thirdly, jQuery('final').hide() is missing the # denoting you're targeting by element ID.
Fourthly, the line
$('#final').html($('#final').html().replace('','result + " text"'));
...doesn't quite do what you think it does. For one thing, it makes no reference to your data variable. And running replace() on an empty string doesn't make much sense.
All in all I'm guessing you want something like (note also how I cache the #final element - that's better for perforamnce):
jQuery(function() { //<-- another way to write a document-ready handler
let el = jQuery('#final');
el.hide();
jQuery("#form").submit(function(e){
e.preventDefault();
const data = jQuery(this).serializeArray();
let calc = 5+2; //<-- do what you need to here
el.html(calc).show();
}
}
Guessing result is your variable and your above code is your current status, you should fix the html replacement to something like (depending on your acutal usecase):
$('#final').html(result + " text"));

Hide character with jQuery inside a span with a class

I've looked for the solution to this but nothing seems to be working.
I have an SKU within a span with a class of "sku". Some of the SKUs have periods before the SKU to allow for adding more than one product with the same SKU.
I'd like to hide the periods when the SKU is displayed though.
This is my code:
<span class="sku">..THESKU</span>
And this is the jQuery I am using:
<script>
$('span.sku').html($('span.sku').html().replace('.',''));
</script>
Is the right, or am I missing something? Thanks.
Your code will only replace one dot '.'. You can use regex to remove all the dots instead:
const skus = $('span.sku');
$('span.sku').each(function() {
const text = $(this).html();
const cleaned = text.replace(/\./g,'');
$(this).html(cleaned);
})
Hope this helps!
EDIT: Updated as suggested by #Taplar
I just wanted to give an update with this. I still couldn't get the periods to hide, but I found a way to have duplicate SKUs so there was no longer a need for this. Thanks for all your help.
If anyone has a similar issue, the code I used is below which I added to the themes functions file.
add_filter( 'wc_product_has_unique_sku', '__return_false', PHP_INT_MAX );

using href or routerlink with #

I'm fairly new to changing paths / position of page so I would like a little help on this.
Say, when a button is clicked, I want to scroll down to another portion of the page. (where id of that section is 'xyz') however, I'm using an entirely different component to access that section.
If I were to use href, I can easily do : href="/app/appid#xyz"
however, if appid is a variable retrieved from the ts file, how can I insert it into my href?
It's easier to to use [routerlink]="['app', appid]" but how can I insert the "#xyz" into my string?
Or is there a completely separate and easier functionality I can use?
Thank you
Add the frament attribute:
<a [routerLink]="['app', appid] fragment="xyz">Link</a>
https://angular.io/api/router/RouterLink

Don't show all the row information (only when I press "view")

I have a strange question !
I made a simple create/delete notes form and a script to query them all.But it will not be beautiful if someone inserts a 100KM note and the table shows it all.
I please you to suggest me a script that shows only some content of the row, and the rest when you press something like "view all".
For example :
You need to look into truncating the content string, there's a load of answers available here for both JavaScript and PHP based solutions:
JavaScript: smart way to shorten long strings with javascript
PHP: Shorten string with a "..." body
So you show the truncated string to begin with and then on the full view use the original string.
Depending on how your table in the example is setup you could also try using CSS to truncate and have it add the elipses as well.
CSS: http://css-tricks.com/snippets/css/truncate-string-with-ellipsis/
Well, I think you want something like this:
Live jsfiddle
js
$(function()
{
var maxShow = 50;
$( ".holder" ).each(function()
{
var txt = $(this).text();
txt = txt.substr(0,maxShow)+' ...';
$(this).prev().prev().text(txt);
});
$(".show").click(function()
{
var txt = $(this).next('span').text();
$(this).parent().text(txt);
});
});
html
<div class='txt'><span class='summery'></span>view<span class='holder'> 0 I have a strange question ! I made a simple create/delete notes form and a script to query them all.But it will not be beautiful if someone inserts a 100KM note and the table shows it</span></div>
<div class='txt'><span class='summery'></span>view<span class='holder'> 1 I have a strange question ! I made a simple create/delete notes form and a script to query them all.But it will not be beautiful if someone inserts a 100KM note and the table shows it</span></div>
<div class='txt'><span class='summery'></span>view<span class='holder'> 2 I have a strange question ! I made a simple create/delete notes form and a script to query them all.But it will not be beautiful if someone inserts a 100KM note and the table shows it</span></div>
css
.holder
{
display:none;
}

creating a hyperlink from a form select value

I would like to make a simple drop down menu when you click your choice from the list, it acts as a link.
Sorry for title being so ambiguous, I just do not have any idea what to call this.
The easiest way is to create a select list with attributes representing the links, then use JavaScript to jump to a link when it's clicked.
But a more accessible way would be to create a list of links, then use JavaScript to construct a select list from them. This way, the links would still work if JavaScript was turned off.
With jQuery, something like:
Link 1
Link 2
And your script is:
var $sel = $("<select/>")
.appendTo("body")
.change(function() {
document.location.href = $sel.val();
})
$("a").each(function() {
$("<option/>")
.appendTo($sel)
.val(this.href)
.html(this.innerHTML)
});
Do you mean that when you select an option from a drop-down, the browser goes to a different URL?
If so, here's a good page that describes how to accomplish that: http://www.davesite.com/webstation/js/theory1jump.shtml