logo
down
shadow

Check each paragraph contains any bold element with jQuery


Check each paragraph contains any bold element with jQuery

Content Index :

Check each paragraph contains any bold element with jQuery
Tag : jquery , By : zac
Date : December 01 2020, 05:00 PM

To fix this issue Use :has() selector in association with :not() selector
$('p:not(:has(b))').css('background-color', 'yellow');
$('p').not(':has(b)').css('background-color', 'yellow');
$(document).ready(function() {
  $('p:not(:has(b))').css('background-color', 'yellow');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<h1>Welcome to My Homepage</h1>

<p class="intro">My name is Donald.</p>
<p><b>I live in Duckburg.</b>
</p>
<p>My best friend is Mickey.</p>

Who is your favourite:
<ul id="choose">
  <li>Goofy</li>
  <li>Mickey</li>
  <li>Pluto</li>
</ul>

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

jQuery: Check for existence of BR as first or last element, including text nodes within a paragraph


Tag : javascript , By : Kyle
Date : March 29 2020, 07:55 AM
Does that help This is easy using universally supported DOM properties. jQuery isn't much use here.
function isBr(el) {
    return el && el.nodeType == 1 && el.tagName == "BR";
}

function isWhitespaceNode(node) {
    return node.nodeType == 3 && /^\s*$/.test(node.data);
}

function isFirstOrLastChildBr(el) {
    var first = el.firstChild;
    if (isWhitespaceNode(first)) first = first.nextSibling;
    if (isBr(first)) return true;

    var last = el.lastChild;
    if (isWhitespaceNode(last)) last = last.previousSibling;
    if (isBr(last)) return true;

    return false;
}
var $foo = $("#foo");
if ( isFirstOrLastChildBr($foo[0]) ) {
    $foo.addClass("diog-fail brbr");
}
// All paragraphs
$("p").filter(function() {
    return isFirstOrLastChildBr(this);
}).addClass("diog-fail brbr");

jQuery mouseenter on paragraph with bold text


Tag : jquery , By : Vinicios
Date : March 29 2020, 07:55 AM
Hope this helps I have a paragraph with a bold text inside , You have to use mouseleave event instead of mouseout..
$('.class1').mouseenter(function(){
    $(this).addClass("highlight");
});

$('.class1').mouseleave(function(){
    $(this).removeClass("highlight");
});

how to fit the original text format of a paragraph into the html paragraph element using jquery?


Tag : javascript , By : jedameron
Date : March 29 2020, 07:55 AM
Hope that helps The original issue
To make the section where your comment appears scale with content length, you need to replace the following html:
<p id ="content" class="minimize more"  style ="width :500px; height :100px; white-space :pre ">
<p id ="content" class="minimize more"  style ="width :500px; min-height :100px; white-space :pre ">

jQuery - Making every even number in a paragraph bold


Tag : javascript , By : ┬Áilad
Date : March 29 2020, 07:55 AM
it fixes the issue You need to change for loop condition to i < numbers.length, use length property to get array size
$("button").on("click", function() {
  var countNumbers = Number($("input[type=number]").val());
  for (var i = 0; i < countNumbers; i++) {
    var rand = Math.floor(Math.random() * 15000);
    $("#numbers").text($("#numbers").text() + rand + " ");
  }

  var numbers = $("#numbers").text().split(' ');
  for (var i = 0; i < numbers.length; i++) {
    //------------------------^-----------
    if (Number(numbers[i]) % 2 === 0) {
      numbers[i] = "<span class='bold'>" + numbers[i] + "</span>";
    }
  }
  $("#numbers").html(numbers.join(' '));
});
.bold {
  font-weight: bold
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="number" />
<button>Generate Numbers</button>
<p id="numbers"></p>
$("button").on("click", function() {
  var countNumbers = Number($("input[type=number]").val());
  var res = [];
  // array for storing the random number
  for (var i = 0; i < countNumbers; i++) {
    var rand = Math.floor(Math.random() * 15000);
    // generating random number
    res.push(rand % 2 == 0 ? "<span class='bold'>" + rand + "</span>" : rand);
    // checking even or odd and wrapping by span if needed finally  pushing the string to array
  }
  $("#numbers").html(res.join(' '));
  // joining the array value and set it as html
});
.bold {
  font-weight: bold
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="number" />
<button>Generate Numbers</button>
<p id="numbers"></p>

setting caret (cursor) inside bold element present inside contenteditable paragraph


Tag : javascript , By : 66.
Date : March 29 2020, 07:55 AM
Hope this helps It's pretty much impossible to move the cursor into an empty element in a contenteditable div. However, as shay levi suggested in another post, you can insert the zero-width character ÈB into your empty element to give it an index value.
Here's an example*:
function insertNode(nodeName) {
  var sel = window.getSelection(),
    range;
  range = sel.getRangeAt(0);
  range.deleteContents();

  var child = document.createElement(nodeName);
  child.innerHTML = '&#8203;';
  range.insertNode(child);
}

var div = document.querySelector('div'),
  btn = document.querySelector('button');

btn.addEventListener('click', function() {
  insertNode('strong');
  div.focus();
});

div.focus();
<div contenteditable></div><button><strong>B</strong></button>
Related Posts Related QUESTIONS :
  • jquery syntax function(){mylongfunc();} vs. just mylongfunc();
  • jQuery.load doesn't execute javascript with document.write
  • Animate hidden hyperlink to display:block
  • jquery ajax call returning error when its not an error
  • Exclude one or more elements from being connected (using connectWith) in jQuery's sortable lists
  • Adding link with existing href
  • jquery cycle plugin divs always stacked problem
  • jquery toggle and fade in one function?
  • JQuery UI Tabs caching
  • Drag and Drop into another div and move in the div only using jquery
  • Links in rounded boxes? In ALL browsers (yep included IE8)
  • How to change the content of the Span using jQuery?
  • jQuery; combine user click and :checked
  • jQuery - Finding the element index relative to its container
  • jQuery .each() function. Resetting the index?
  • jQuery storing settings
  • Why does asp.net mvc form submits itself on button clicks when javascript function error?
  • Linking to non-home panel in JQTouch site
  • How to Edit jQuery Table Using CSS
  • Jquery hover triggers "mouse leave" without cursor leaving
  • DELETE http://localhost:8000/product/[object%20Object] 500 (Internal Server Error)
  • Comparing two string arrays and returning key of not found element using jquery
  • using jquery to change list items is changing all list items, when i want to only change one list item
  • Sending a Json data from my html page to a php
  • Click function to search a specific element in a Json object
  • Bootstrap 4 - Progress Bar Progression
  • how to deleted item materialize chips
  • jQuery - Hide non-active elements using filter()
  • Adding style to string table is not working
  • Github merge multiple files into single compressed master file
  • Replace characters in a field on page load
  • Unable to send data from Form to SQL database
  • If all divs have same style, remove element
  • How to click a jQuery Dialog button in TestCafe
  • Cannot reinitialise DataTable with Angular Datatable
  • How to add Class active on Click in Navbar
  • how to call fail method into jquery.get/post success method?
  • Slider with tabs
  • Jquery Get parent element from data function
  • Ho to put a new line in <p> tag in my jquery?
  • How can I use a text value as a mathematical operator?
  • DataTable columns values showing Only DefaultContent
  • JQuery select dynamically added elements
  • How to change an image source on hover?
  • How to bind jquery event to dynamically added multiple DOM elements?
  • How to get td values and store in array using Jquery?
  • How to add handler to dinamically created tr in JQuery?
  • How to Covert Html to PDF in Jquery?
  • Jquery before() and after() used to create a <div> container not inserting closing tags in after()
  • I want to delete previously added class
  • Open html page in same window after clicking on navlink
  • Datatable is not working when I populate table using smarty
  • How to change image based on the offset top of the content div
  • Find the index of table column with specific id
  • How to return value of $(window).resize()
  • How to optimize adding numerous elements dynamically into web page
  • Content slide down on top of page?
  • How to write if statement for when a specified option is selected in select tag in JQuery
  • HTML tags remove from textarea using jQuery
  • ShareThis not display properly when initially hidden
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com