This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
Testen ob es Sprungmarken gibt
#1
Testet  ob es eine Sprungmarke gibt oder nicht.
DEMO  

CODE;
<!DOCTYPE html>
<html>
<head>
   <title>Listen to File Update</title>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<style>
body{
 height:1000px;
}

#as{
 margin-top:1200px;
 font-size:100px;
 color:red;
}

a{
 padding-left:20%;
}

</style>
</head>
<body>
<a href="#as">Sprung was es gibt</a>
<a href="#aa">Sprung was es nicht gibt</a> 
<div id="as">Gesprungen</div>
<script>

$('a').click(function(){
 marke=$(this).attr('href');
 marke=marke.split('#')[1];
 if(document.getElementById(marke)){
   //alert('Sprung marke exestiert')
 }else{
 alert('sprung marke gibt esnicht');
 }
})
</script>
</body>
</head>
Zitieren
#2
Moin, das geht auch gut ohne jQuery mit Vanilla JavaScript.

Hier ein Codebeispiel - schnell mal zuhause zusammen getippt:

'use strict';
var sprungCount = 0;
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('a').forEach((element) => {
	let currentAttr = element.getAttribute('href');
	if(currentAttr.includes('#')) {
		sprungCount++; 
	}
	if(sprungCount>0) {
		alert('Sprungmarken sind vorhanden!');
	} else {
		alert('Keine Sprungmarken vorhanden!');
	}
});
});


Viel Spass beim ausprobieren.

Gruss scoutrz
Als Lösung markieren Zitieren


Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste