admin管理员组文章数量:1241086
My Question is How would I change the text of a HTML <p>
tag when I am on a mobile device like android or iphone?
Here is my current code p
tag:
<p>You are on a desktop good</p>
This is the <p>
tag I want to appear on Desktop, Tablet and Laptop.
How can I make it so that it says the following on mobile device like android or iphone in Straight Up Javascript no bootstrap just JavaScript?
<p>Please Use a Desktop to view</p>
Please Help
Thank You For All answers
My Question is How would I change the text of a HTML <p>
tag when I am on a mobile device like android or iphone?
Here is my current code p
tag:
<p>You are on a desktop good</p>
This is the <p>
tag I want to appear on Desktop, Tablet and Laptop.
How can I make it so that it says the following on mobile device like android or iphone in Straight Up Javascript no bootstrap just JavaScript?
<p>Please Use a Desktop to view</p>
Please Help
Thank You For All answers
Share Improve this question edited Feb 12, 2016 at 2:40 The Beast asked Dec 7, 2015 at 23:08 The BeastThe Beast 1 5- Are you using bootstrap? – Franco Commented Dec 7, 2015 at 23:11
- no i am not using bootstrap – The Beast Commented Dec 7, 2015 at 23:11
- css classes + media queries? – 0x860111 Commented Dec 7, 2015 at 23:12
- What have you tried? Use media queries and show one div at a certain breakpoint and hide the other. – j08691 Commented Dec 7, 2015 at 23:12
- Than you need to use a media query in your CSS file. Do you know what a media query is? – Franco Commented Dec 7, 2015 at 23:12
2 Answers
Reset to default 11gives a id or specific class to your <p> tag and include the JS after the dom loaded
<p id="changeMe">Services</p>
<script>
if (navigator.userAgent.match(/Mobile/)) {
document.getElementById('changeMe').innerHTML = 'Services Are everywhere';
}
</script>
Or use css Media Queries to show and hide Paragraphs
<p class="desktop"> Services</p>
<p class="mobile"> Services Are everywhere </p>
CSS:
p.mobile { display: none }
@media (max-width: 640px) {
p.mobile { display: block }
p.desktop { display: none }
}
You can use CSS media queries, and use elements to show or hide the element based on the screen width.
For example:
p.mobile {
display: none;
}
p.desktop {
display: auto;
}
@media screen and (max-width: 480px) {
p.mobile {
display: auto;
}
p.desktop {
display: none;
}
}
Using a desktop
and mobile
class on everything that should be on desktop or mobile (exclusive) is important, so that this style will work on all of those elements that you want to change.
本文标签: htmlHow to change text of element when on mobile device JavascriptStack Overflow
版权声明:本文标题:html - How to change text of element when on mobile device Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740037601a2221539.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论